OutputModerate2 marks
Write the output of the following String method: String x = "talent"; String y = "matrix"; System.out.print(x.substring(3).concat(y.substring(3)));
Topic: substring() and concat()
Previous-year question practice database
Answer
Exam answer
entrix
Explanation
Take it one call at a time. x.substring(3) on "talent": counting from index 0 (t=0, a=1, l=2, e=3), it returns everything from index 3 to the end, so "ent". y.substring(3) on "matrix": m=0, a=1, t=2, r=3, so it returns "rix". concat() joins the second to the end of the first, giving "ent" + "rix" = entrix. Remember: substring(n) with one argument runs to the end of the string; substring(a, b) stops just before index b.
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