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
40 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
18 Likes
Related Questions
Write a Java program to enter any sentence and convert the sentence to uppercase. Print only those words of the sentence whose first and last letters are the same.
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@2024Write the output of the following String methods:
String x= "Galaxy", y= "Games";(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));