Output using System.out.
From CompSciWiki
Contents
Output using System.out.
Java uses System.out. for program output.
Printing text to the screen
To print text to the screen you can use:
System.out.println("text");
or
System.out.print("text");
Whatever you put inside of the quotes will be printed to the screen. The difference between System.out.println and System.out.print is that System.out.println will print a newline after the text unlike System.out.print which just prints the text.
Example 1
This program prints the message "Go Bisons!" to the screen.
public class Output { public static void main(String args[]) { System.out.println("Go Bisons!"); } }
Example 2
This program prints the message "Go Bisons!" to the screen three times.
public class Output { public static void main(String args[]) { System.out.println("Go Bisons!"); System.out.println("Go Bisons!"); System.out.println("Go Bisons!"); } }
Output
Go Bisons! Go Bisons! Go Bisons!
Example 3
This program also prints the message "Go Bisons!" to the screen three times. However, it does not print a new line after each message.
public class Output { public static void main(String args[]) { System.out.print("Go Bisons!"); System.out.print("Go Bisons!"); System.out.print("Go Bisons!"); } }
Output
Go Bisons!Go Bisons!Go Bisons!