Computer Applications
State the output of the following program segment:
String str1 = "great"; String str2 = "minds";
System.out.println(str1.substring(0,2).concat(str2.substring(1)));
System.out.println(("WH" + (str1.substring(2).toUpperCase())));
Java
Java String Handling
ICSE 2014
17 Likes
Answer
The output of the above code is:
grinds
WHEAT
Explanation:
- str1.substring(0,2) returns "gr". str2.substring(1) returns "inds". Due to concat both are joined together to give the output as "grinds".
- str1.substring(2) returns "eat". It is converted to uppercase and joined to "WH" to give the output as "WHEAT".
Answered By
7 Likes
Related Questions
Which of the following returns a String?
- length()
- charAt(int)
- replace(char, char)
- indexOf(String)
The output of the statement "talent".compareTo("genius") is:
- 11
- –11
- 0
- 13
Write a Java program to enter any sentence and convert the sentence to uppercase. Print only those words of the sentence whose first and last letters are the same.