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
6 Respostas
+ 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 :)
+ 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
0
does System.out.print even exist
0
well according to my java class lol
0
thank you so much! you are the best!! I love your examples as well.
0
yes they exist and are both basically the same thing