Problem Statement - Use of substring, toUpperCase and equalsIgnoreCase()
State the output of 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));
Solution
TC++ #3980
String a = “Smartphone”, b = “Graphic Art”;
String h = a.substring(2, 5);
h would be “art” as character index 2 would be a and index 5 would be t
String k = b.substring(8).toUpperCase();
k would be “ART” as from index 8 till end would be “Art” and its upper case would be returned.
System.out.println(h);
This will print art
System.out.println(k.equalsIgnoreCase(h));
This will print true as after ignoring case both art and ART would be same.