
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Print Single and Multiple variables in Java
To print single and multiple variables in Java, the code is as follows −
Example
public class Demo { public static void main(String args[]){ String name_1 = "Hello"; String name_2 = "World"; System.out.println("Printing single variable"); System.out.printf("%s", name_1); System.out.println("\nPrinting multiple variables"); System.out.printf("First Name: %s\nLast Name: %s",name_1, name_2); } }
Output
Printing single variable Hello Printing multiple variables First Name: Hello Last Name: World
A class named Demo contains the main function, which defines two strings. These strings are displayed using the ‘println’ function and using the ‘printf’ function.
- Related Articles
- Print Single and Multiple variable in Python?
- Print Single and Multiple variable in C#
- How to assign same value to multiple variables in single statement in C#?
- What are class variables, instance variables and local variables in Java?
- How can we insert multiple tabs into a single JTabbedPane in Java?
- Is it possible to catch multiple Java exceptions in single catch block?
- Multiple index variables in PHP foreach loop
- What are single row and multiple row subqueries?
- Global and Local Variables in Java
- Class and Static Variables in Java
- Multiple COUNT() for multiple conditions in a single MySQL query?
- How do I add multiple items to a Java ArrayList in single statement?
- Select multiple columns and display in a single column in MySQL?
- C program to print environment variables
- Multiple Assignments to Single Value in Python

Advertisements