Website For Developers

Output in Java



The result of the program is the output of the program.

In this tutorial, we cover only console output.

In java, there are four ways of output or print statements:

Let see the examples of all these methods.

Syntax

System.out.method_name();


1- System.out.print

Output in Java Example#1

public class Print {
   public static void main(String[] args) {

     System.out.print( "Hello. " );
     System.out.print( "How's The Weather?" );
   }
}

Output

Hello. How's The Weather?


2- System.out.println

Output in Java Example#2

public class Println {
   public static void main(String[] args) {

     System.out.print( "Hey. " );
     System.out.print( "What New" );
   }
}

Output

Hey.
What New?



3- System.out.printf

Output in Java Example#3

public class Printf {

   public static void main(String[] args) {
     int a = 10;
     double b = 10.01;
     String s = "We dont like Coding, We love coding.";
     System.out.printf("%d %n",a);
     System.out.printf("%f %n",b);
     System.out.printf("%s",s);
   }
}

Output

10
10.010000
We dont like Coding, We love coding.



4- System.err.println

Output in Java Example#4

public class Println {
   public static void main(String[] args) {

     System.err.println( "Hello. How are you?" );
   }
}

Output

Hello. How are you?