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"));
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.
Related Questions
Define a class to accept a string and convert the same to uppercase, create and display the new string by replacing each vowel by immediate next character and every consonant by the previous character. The other characters remain the same.
Example:
Input : #IMAGINATION@2024
Output : #JLBFJMBSJPM@2024The output of the statement "talent".compareTo("genius") is:
- 11
- –11
- 0
- 13