In java you will find these two statements (System.out.println & System.out.print) used many times. println will print the statement in new line. Consider println as Print new line. While System,out.print keeps printing to the same line.
Let’s try the below program,
public class Hello{
public static void main(String[] args){
int x=1;
while (x <3) {
System.out.println(“First loop”);
System.out.print(“2nd Command”);
x=x+1;
}
}
}
The output will appear as,
You can see that println displayed the statement in new line and print displayed the statement in same line.
Advertisements