Java offers rich functionality for printing messages and handling errors.
In Java, the System.out.println method is commonly used to print messages to the console. It's akin to displaying a smoothie after blending ingredients—the output is the result of your coded instructions.
Java distinguishes between regular output and error messages through System.out and System.err, respectively.
Java provides several ways to take user input, and one of the most common methods is using the Scanner class from the java.util package.
To use the Scanner class, we first need to import it from the java.util package at the beginning of our Java program. This is done with the import statement.
import java.util.Scanner;
After importing the Scanner class, we can now use it to read various types of input from the console. We create a Scanner object by passing System.in to its constructor. System.in is an InputStream which is connected to the keyboard input.
Scanner sc = new Scanner(System.in);