Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java 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);
}
}

What will be the output of the following Java 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);
}
}
a) 4 8
b) 5 9
c) 4 9
d) 5 8

Answer: c
Explanation: indexOf() method returns the index of first occurrence of the character where as lastIndexOf() returns the index of last occurrence of the character.
output:
4 9

Join The Discussion