OutputModerate2 marks
Write the output for the following: System.out.println("Incredible" + "\n" + "world");
Topic: Escape sequences
Previous-year question practice database
Answer
Exam answer
Incredible world
Explanation
\n is the newline escape sequence. Although it is written with two symbols, it represents a SINGLE character that moves the output to the next line. The + operators simply join the three pieces into one string, so the text printed is Incredible, then a line break, then world. Note the difference from a literal: "\\n" with two backslashes would print the characters \n rather than breaking the line.
More from String Manipulation
To extract the word NOW from the word "ACKNOWLEDGEMENT", the Java statement "ACKNOWLEDGEMENT".substring(3, ____) is used. Choose the correct number to fill in the blank.2026String a[] = {"Atasi", "Aditi", "Anant", "Amit", "Ahana"};
System.out.println(a[1].charAt(1) + "*" + a[2].charAt(2));
The output of the above statement is:2026Which of the following String methods returns a negative value?2026Assertion (A): The substring() method modifies the original String.
Reason (R): The substring() method can extract part of a String starting from a specific index.2026Give the output of the following program segment:
String S = "GRACIOUS".substring(4);
System.out.println(S);
System.out.println("GLAMOROUS".endsWith(S));2026Name the following:
(a) The return data type of the method equals().
(b) The String method which has no parameter and returns a String.2026