KnowledgeBoat Logo
|

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:

  1. str1.substring(0,2) returns "gr". str2.substring(1) returns "inds". Due to concat both are joined together to give the output as "grinds".
  2. 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