Computer Applications

Write the output for the following:

String s1 = "Life is Beautiful";
System.out.println("Earth" + s1.substring(4));
System.out.println(s1.endsWith("L"));

Java

Java String Handling

33 Likes

Answer

Earth is Beautiful
false

Working

s1.substring(4) will return a substring starting at index 4 of s1 till its end so its output will be " is Beautiful". System.out.println("Earth" + s1.substring(4)) will concatenate "Earth" and " is Beautiful" to given the output as "Earth is Beautiful".

As the last character of s1 is a small l not a capital L so s1.endsWith("L") returns false.

Answered By

16 Likes