Computer Applications
Which of the following statements correctly prints the following output?
Hello
World
Answer
System.out.println("Hello\nWorld");
Reason — Let's analyze each of the options:
1. System.out.println("Hello/nWorld"); — Incorrect
\nis a special escape sequence, but/n(forward slash) is not. Output would be:Hello/nWorld
2. System.out.println("Hello\\nWorld"); — Incorrect
\\nprints as\nliterally (because\\is an escape character for\). Output would be:Hello\nWorld
3. System.out.println("Hello World"); — Incorrect
- Prints everything on a single line. Output would be:
Hello World
4. System.out.println("Hello World"); — Correct
- The
\n(newline escape sequence) moves the cursor to the next line. Output would be:
Hello
World
Related Questions
Applet programming is a feature of which language:
- C
- C++
- Java
- BASIC
…………… statement displays the result in Java programming.
- System.print()
- Print()
- System.printout()
- System.out.println()
"Java compiled code (byte code) can run on all operating systems"
— Name the feature.- Robust and Secure
- Object Oriented
- Platform Independent
- Multithreaded