Sail E0 Webinar
Question


What is the output of this program?


class output {
public static void main(String args[])
{ String s = "Hello World";
int i = s.indexOf('o');
int j = s.lastIndexOf('l');
System.out.print(i + " " + j);
}
}
Options:
A .  4 8
B .  5 9
C .  4 9
D .  5 8
Answer: Option C

indexOf() method returns the index of first occurrence of the character where as lastIndexOf() 

returns the index of last occurrence of the character.
output:
$ javac output.java
$ java output
4 9



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers