✏️ Explanatory Question

What is the statement to display a string on the console?

👁 3,027 Views
📘 Detailed Answer
💡

Answer with Explanation

In Java, you can use the System.out.println() statement to display a string on the console. Here's an example:


public class HelloWorld {
    public static void main(String[] args) {
        // Displaying a string on the console
        System.out.println("Hello, World!");
    }
}

In this example, the string "Hello, World!" is passed as an argument to the println method of System.out, which is responsible for standard output (usually the console). The println method prints the string to the console followed by a newline character.