Home / Questions / What is the statement to display a string on the console?
Explanatory Question

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

👁 3,026 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

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.