E04- Difference between println & print

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,

 

Untitled

You can see that println displayed the statement in new line and print displayed the statement in same line.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s