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));

Views 11

Answer:

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.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.