array.length() and substring() – Computer Sir Ki Class

Login


Lost your password?

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

Login
[lwa]



Exam Questions-ICSE2018-03H #JAVA#4065    siteicon   siteicon  

Problem Statement - array.length() and substring()

Consider the following String array and give the output
String arr[]= {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
System.out.println(arr[0].length()>arr[3].length());
System.out.print(arr[4].substring(0,3));

Solution

TC++ #4065

The outputs will be as follows –
false
JAI

System.out.println(arr[0].length()>arr[3].length());
arr[0].length() would be 5 (character count in DELHI) and arr[3].length() would be 7 (Character count in LUCKNOW). Since 5 is not greater than 7 so output would be false.

System.out.print(arr[4].substring(0,3));
Here arr[4] would be JAIPUR and in this characters from index 0 up to 3 (excluding index 3) would be JAI.


Share

sunmitra| Created: 25-Mar-2018 | Updated: 12-Apr-2019|ICSE2018






Back