QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A ICSE2014-03B #7393

Question:

State the output of the following program segment:

String str1 = "great"; String str2 = "minds";
System.out.println(strl.substring(0,2).concat(str2.substring(l)));
System.out.println(("WH" + (strl.substring(2).toUpperCase())));

Answer:

Output is

grinds
WHEAT

Notes:

Explanation for first print statement:
strl.substring(0,2) gives “gr”
str2.substring(l) “inds”
The two on concatenation gives “grinds”
Explanation for second print statement
strl.substring(2) gives “eat”
“eat” on conversion to upper case using the function toUpperCase() results in EAT
“WH” on concatenation with “EAT” using + gives “WHEAT