Advertisements
Advertisements
Question
Give the output of the following program segment:
String S = "GRACIOUS”.substring(4);
System.out.println(S);
System.out.println ("GLAMOROUS”.endsWith(S));
Long Answer
Advertisements
Solution
IOUS
false
String S = “GRACIOUS”.substring(4);
Thesubstring(4)The method begins extraction from the character at index 4 (where ‘G’ is index 0). In the string “GRACIOUS”, the character at index 4 is ‘I’. Therefore, the value stored inSisIOUS.System.out.println(“GLAMOROUS”.endsWith(S));
TheendsWith()The method checks if the string “GLAMOROUS” ends with the suffix “IOUS”. Since “GLAMOROUS” ends with "ROUS" and not "IOUS", the condition is false. Thus, it printsfalse.
shaalaa.com
Is there an error in this question or solution?
