Print Single and Multiple variables in Java

JavaServer Side ProgrammingProgramming

To print single and multiple variables in Java, the code is as follows −

Example

 Live Demo

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.

raja
Updated on 14-Jul-2020 06:57:00

Advertisements