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
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.
Write a program in Java to enter any sentence. Also ask the user to enter a word. Print the number of times the word entered is present in the sentence. If the word is not present in the sentence, then print an appropriate message.
The output of the statement "talent".compareTo("genius") is:
- 11
- –11
- 0
- 13