nside the main()
method, you can use the println()
method to print a line of text to the screen. Here's a quick recap:
-
System.out.println(): In Java,
System.out
is an object that represents the standard output stream. It provides methods for printing data to the console. Theprintln()
method is one such method, which is used to print a line of text to the console. -
Usage: You can use the
println()
method to display messages, variables, or any other information to the user. It automatically adds a newline character at the end of the output, so each call toprintln()
starts a new line.
public static void main(String[] args) {
System.out.println("Hello World");
}
Note: The curly braces {}
marks the beginning and the end of a block of code.
Note: Each code statement must end with a semicolon.
Practice Excercise Practice now