Home » JAVA Programming » Files and I/O » Question
  1. What is the output of this program?
    public class IndexOf_Example
    {
    public static void main(String args[])
    {
    String str="My first love is java.";
    System.out.println(str.indexOf('i')+" "+str.indexOf('o')+" "+str.lastIndexOf('i')+" "+str.lastIndexOf('j') );
    }
    }
    1. 10 14 17 4
    2. 17 14 10 4
    3. 4 10 14 17
    4. 10 4 14 17
    5. None of these
Correct Option: C

indexof(‘c’) and lastIndexOf(‘j’) are pre defined function which are used to get the index of first and last occurrence of
the character pointed by j in the given array.



Your comments will be displayed only after manual approval.