Menu
Question Index
...

What will be the output of the following program?

public class StringSearch
{
    public static void main(String[] args)
    {
        String searchString = "hai this is string search program, haiii now you are attempting.";
        int lastIndex = searchString.lastIndexOf("hai");

        if(lastIndex == - 1)
        {
            System.out.println("hai not found");
        }
        else
        {
            System.out.println("Last occurrence of hai is at index: " + lastIndex);
        }
    }
}


Last occurrence of hai is at index: 0
Last occurrence of hai is at index: 28
Last occurrence of hai is at index: 35
Last occurrence of hai is at index: 63
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Searching Strings - Java indexOf, lastIndexOf Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App