English

Give the output of the following program segment: String S = "GRACIOUS”.substring(4); System.out.println(S); System.out.println ("GLAMOROUS”.endsWith(S)); - Computer Applications

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
  1. String S = “GRACIOUS”.substring(4);
    The substring(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 in S is IOUS.
  2. System.out.println(“GLAMOROUS”.endsWith(S));
    The endsWith() 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 prints false.
shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×