Use of substring, toUpperCase and equalsIgnoreCase() – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2015-03C #JAVA#3980    siteicon   siteicon  

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.


Share

sunmitra| Created: 22-Mar-2018 | Updated: 16-Apr-2019|ICSE2015






Back