Computer Applications
If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(x.indexOf(x.charAt(4)));
Java
Java String Handling
51 Likes
Answer
4
Working
x.charAt(4) returns the character at index 4 of string x which is 'u'. First index of 'u' in x is 4 so output is 4.
Answered By
26 Likes
Related Questions
If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(x.substring(1,5));If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(x.equals(y));Predict the output of the following Java program snippet:
String S1 = "Computer World"; String S2 = "COMPUTER WORLD"; String S3 = "Computer world"; String S4 = "computer world"; System.out.println(S1 + " equals "+ S2 + " " + S1.equals(S2)); System.out.println(S1 + " equals "+ S3 + " " + S1.equals(S3)); System.out.println(S1 + " equals "+ S4 + " " + S1.equals(S4)); System.out.println(S1 + " equalsIgnoreCase "+ S4 + " " + S1.equalsIgnoreCase(S4));
If:
String x = "Computer";
String y = "Applications";
What do the following function returns?
System.out.println(y + x.substring(5));