KnowledgeBoat Logo

Computer Applications

The output of a program which extracts a part of the string "SUBMISSION" is as follows:

(a) "MISS"
(b) "MISSION"

If String str = "SUBMISSION"; write appropriate Java statements to get the above outputs.

Java String Handling

3 Likes

Answer

(a) str.substring(3, 7);
(b) str.substring(3);

Reason

For Output (a): "MISS"

substring(3, 7):

  • Extracts the substring starting from index 3 (inclusive) to index 7 (exclusive).
  • In "SUBMISSION":
    • Index 3 → 'M'
    • Index 4 → 'I'
    • Index 5 → 'S'
    • Index 6 → 'S'
  • Result: "MISS"

For Output (b): "MISSION"

substring(3):

  • Extracts the substring starting from index 3 to the end of the string.
  • In "SUBMISSION":
  • Starting at index 3 → "MISSION"
  • Result: "MISSION"

Answered By

2 Likes


Related Questions