System.out.print Versus System.out.println

By Lon Hosford

 
System.out.print is just like System.out.println except no new line is created.
 
You can use System.out.print to print more than one item on the same line but use more than one line of code.
 
// Using System.out.println
 
String myFirstName = "Willy";
String myLastName = "Nilly";
System.out.println( "My name is " + myFirstName + " " + myLastName );
My name is Willy Nilly
// Same output but using System.out.print
 
String myFirstName = "Willy";
String myLastName = "Nilly";
System.out.print( "My name is " );
System.out.print( myFirstName );
System.out.print( " " );
System.out.println( myLastName );
My name is Willy Nilly