Sunday, February 3, 2019

Java Println

println( ) method

The println( ) method prints the output in the next line of the previous result on the screen.
Example
  1. package test;  
  2. public class Test  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.         System.out.println("first statement.");  
  7.         System.out.println("second statement.");  
  8.         System.out.println("third statement.");  
  9.     }  
  10. }   
Output
println( )
Using Real Numbers and Integers in println( )
The following is a sample of using real numbers and integers in println( ):
  1. package test;  
  2. public class Test  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.        int x = 5;  
  7.        int y = 10;  
  8.         System.out.println(x+y);  
  9.         System.out.println("x+y");  
  10.         System.out.println("" + x + y);  
  11.         System.out.println("5" + "10");  
  12.         System.out.println(5 + 10 + x + y);  
  13.         System.out.println("output " + (x + y));  
  14.         System.out.println("output " + x + y);  
  15.     }  
  16. }  
Output
real no and integers in println( )
Concatenation in println( )
The following is a sample of concatenation in println( ):
  1. package test;  
  2. public class Test  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.        int x = 5;  
  7.        String w = "wooooo";  
  8.        System.out.println(x + " " + "yahooo " + w);  
  9.     }  
  10. }  
Output
concatenation
Printing Characters Using println( )
The following is a sample of printing characters using println( ):
  1. package test;  
  2. public class Test  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.         char c = 67;  
  7.         char d = 'C';  
  8.         char e = 69;  
  9.         char f = 'E';  
  10.         System.out.println(c);  
  11.         System.out.println(d);  
  12.         System.out.println(e);  
  13.         System.out.println(f);  
  14.     }  
  15. }  
Output
printing characters
Escape Sequences in println( )
The following is a sample of Escape Sequences in println( ):
  1. package test;  
  2. public class Test  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.         int x = 5;  
  7.         int y = 6;  
  8.         int z = 7;  
  9.         int m = 8;  
  10.         System.out.println(x+"\n"+ y+"\n"+ z+"\t"+ m);  
  11.     }  
  12. }  
Output
Also Read: Java Interview Questions class and object in Java Java Constructor Wells Fargo Routing Number Bank of America Routing Number
liteblue java collections interview questions java string interview questions java exception handling interview questions

No comments:

Post a Comment

Java String Interview Questions and Answers

1) What is String in Java? Is String is data type? String in Java is not a primitive data type like int, long or double. The string is a ...