0

what is the difference between system.out.print and system.out.printIn

what is the difference between system.out.print and system.out.printIn

6th Oct 2017, 1:04 AM
Martin Renteria Jr
6 odpowiedzi
+ 12
"System.out.println" creates a new line afterwards the print whereas "System.out.print" does not. Example #1: System.out.print("Hello"); System.out.println("Hello"); System.out.print("Hello"); Output: HelloHello Hello Example #2: System.out.print("Hello"); System.out.print("Hello"); System.out.print("Hello"); Output: HelloHelloHello Edit: No Problem :)
6th Oct 2017, 1:23 AM
LynTon
LynTon - avatar
+ 6
Just to add some potentially useful information, System.out.print() is very useful when taking user input, as the input doesn't appear on a new line. For example (assuming java.util.Scanner is imported): Code: System.out.println("Enter a number: "); Scanner input = new Scanner(System.in); Output: Enter a number: // input here Code for when print() is used: Code: System.out.print("Enter a number: "); Scanner input = new Scanner(System.in); Output: Enter a number: // input here TL;DR: print() is ideal for getting user input, where println() is best for printing regular text. :D
6th Oct 2017, 2:02 AM
LunarCoffee
LunarCoffee - avatar
0
does System.out.print even exist
6th Oct 2017, 1:08 AM
Joshua
Joshua - avatar
0
well according to my java class lol
6th Oct 2017, 1:10 AM
Martin Renteria Jr
0
thank you so much! you are the best!! I love your examples as well.
6th Oct 2017, 1:31 AM
Martin Renteria Jr
0
yes they exist and are both basically the same thing
8th Oct 2017, 3:55 AM
Styxincewa
Styxincewa - avatar