Home / Questions / State the output when the following program segment is executed: String a ="Smartphone", b="Graphic Art"; String h=a.substring(2, 5); String k=b.substring(8).toUpperCase(); System.out.println(h); System.out.println(k.equalsIgnoreCase(h));
Explanatory Question

State the output when the following program segment is executed:

String a ="Smartphone", b="Graphic Art";
String h=a.substring(2, 5);
String k=b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));

👁 78 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

The output of the above code is:


art
true
Explanation

a.substring(2, 5) extracts the characters of string a starting from index 2 till index 4. So h contains the string "art". b.substring(8) extracts characters of b from index 8 till the end so it returns "Art". toUpperCase() converts it into uppercase. Thus string "ART" gets assigned to k. Values of h and k are "art" and "ART", respectively. As both h and k differ in case only hence equalsIgnoreCase returns true.