Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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.
Advertisements
