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.
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 index7(exclusive). - In "SUBMISSION":
- Index 3 →
'M' - Index 4 →
'I' - Index 5 →
'S' - Index 6 →
'S'
- Index 3 →
- Result:
"MISS"
For Output (b): "MISSION"
substring(3):
- Extracts the substring starting from index
3to the end of the string. - In "SUBMISSION":
- Starting at index 3 →
"MISSION" - Result:
"MISSION"