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 a = “hello i love java”;
System.out.println(a.indexOf(‘e’)+” “+a.indexOf(‘a’)+” “+a.lastIndexOf(‘l’)+” “+a.lastIndexOf(‘v’));
}
}

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

Answer: d
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:
1 14 8 15

Join The Discussion