Home » JAVA Programming » Characters » Question
  1. What is the output of this program?
    public class Result 
    {
    public static void main(String args[])
    {
    String a = "hello i love interview mania";
    System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
    }
    }
    1. 6 4 26 4
    2. 4 6 21 4
    3. 4 4 6 21
    4. 21 6 4 4
    5. 4 21 6 4
Correct Option: A

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



Your comments will be displayed only after manual approval.