Print Single and Multiple variables in Java

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


 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);


Printing single variable
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.

Updated on: 14-Jul-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started