KnowledgeBoat Logo
|

Computer Applications

Which of the following is a valid statement to print the following sentence:

Raj said "Good morning"

  1. System.out.println("Raj said "Good morning");
  2. System.out.println("Raj said \\Good morning\\);
  3. System.out.println("Raj said \"Good morning\" ");
  4. System.out.println("Raj said Good morning");

Values & Data Types Java

2 Likes

Answer

System.out.println("Raj said \"Good morning\" ");

Reason — The statement System.out.println("Raj said \"Good morning\" "); is valid because it uses the escape sequence \" to include double quotes inside the string. This ensures the output displays exactly as Raj said "Good morning".

Answered By

1 Like


Related Questions