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 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
3
to the end of the string. - In "SUBMISSION":
- Starting at index 3 →
"MISSION"
- Result:
"MISSION"
Answered By
2 Likes
Related Questions
Consider the following program segment in which the statements are jumbled, choose the correct order of statements to check if a given word is Palindrome or not.
boolean palin(String w) { boolean isPalin; w = w.toUpperCase(); int l = w.length(); isPalin = false; // Stmt (1) for (int i = 0; i < l / 2; i++) { char c1 = w.charAt(i), c2 = w.charAt(l - 1 - i); // Stmt (2) if (c1 != c2) { break; // Stmt (3) isPalin = true; // Stmt (4) } } return isPalin; }
Write the output of the following String methods:
String x= "Galaxy", y= "Games";
(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));
The output of the statement "CONCENTRATION".indexOf('T') is:
- 9
- 7
- 6
- (-1)
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)