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.
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024Write 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));