println( ) method
The println( ) method prints the output in the next line of the previous result on the screen.
Example
- package test;
- public class Test
- {
- public static void main(String args[])
- {
- System.out.println("first statement.");
- System.out.println("second statement.");
- System.out.println("third statement.");
- }
- }
Using Real Numbers and Integers in println( )
The following is a sample of using real numbers and integers in println( ):
- package test;
- public class Test
- {
- public static void main(String args[])
- {
- int x = 5;
- int y = 10;
- System.out.println(x+y);
- System.out.println("x+y");
- System.out.println("" + x + y);
- System.out.println("5" + "10");
- System.out.println(5 + 10 + x + y);
- System.out.println("output " + (x + y));
- System.out.println("output " + x + y);
- }
- }
Concatenation in println( )
The following is a sample of concatenation in println( ):
- package test;
- public class Test
- {
- public static void main(String args[])
- {
- int x = 5;
- String w = "wooooo";
- System.out.println(x + " " + "yahooo " + w);
- }
- }
Printing Characters Using println( )
The following is a sample of printing characters using println( ):
- package test;
- public class Test
- {
- public static void main(String args[])
- {
- char c = 67;
- char d = 'C';
- char e = 69;
- char f = 'E';
- System.out.println(c);
- System.out.println(d);
- System.out.println(e);
- System.out.println(f);
- }
- }
Escape Sequences in println( )
The following is a sample of Escape Sequences in println( ):
- package test;
- public class Test
- {
- public static void main(String args[])
- {
- int x = 5;
- int y = 6;
- int z = 7;
- int m = 8;
- System.out.println(x+"\n"+ y+"\n"+ z+"\t"+ m);
- }
- }
liteblue java collections interview questions java string interview questions java exception handling interview questions
No comments:
Post a Comment