Computer Applications

Give the output of the following program segment:

String S = "GRACIOUS".substring(4);
System.out.println(S);
System.out.println("GLAMOROUS".endsWith(S));

Java String Handling

5 Likes

Answer

Output
IOUS
false
Explanation
  • The substring() method is used to extract a part of a string starting from a specified index. In the given statement, "GRACIOUS".substring(4) extracts characters from index 4 to the end, resulting in "IOUS".

  • The endsWith() method checks whether a string ends with a specified sequence of characters and returns a boolean value. Here, "GLAMOROUS".endsWith("IOUS") checks if the string ends with "IOUS", which is false, so it prints false.

Answered By

2 Likes


Related Questions