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 code?
class output
{
public static void main(String args[])
{
String a = “hello i love java”;
System.out.println(a.indexOf(‘i’)+” “+a.indexOf(‘o’) +” “+a.lastIndexOf(‘i’)+” “+a.lastIndexOf(‘o’));
}
}

What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String a = “hello i love java”;
System.out.println(a.indexOf(‘i’)+” “+a.indexOf(‘o’) +” “+a.lastIndexOf(‘i’)+” “+a.lastIndexOf(‘o’));
}
}
a) 6 4 6 9
b) 5 4 5 9
c) 7 8 8 9
d) 4 3 6 9

Answer: a
Explanation: indexof(‘c’) and lastIndexof(‘c’) are pre defined function which are used to get the index of first and last occurrence of the character pointed by c in the given array.
Output:
6 4 6 9

Join The Discussion