Menu
Question Index
...

What will be the output of the following program?

class StringSearch {
    public static void main(String[] args)
    {
        String s = "Banana Panama Vikrama Akram Dwakra";
        print(s.indexOf("na"));
        print(s.indexOf("na", s.indexOf("na")));
        print(s.lastIndexOf("na"));
        print(s.lastIndexOf("akr"));
        print(s.lastIndexOf("akr", s.lastIndexOf("akr")));
        System.out.println(s.substring(s.indexOf("ik")-1, s.lastIndexOf("wa")-s.indexOf("Pana")-1));
    }

    private static void print(int value)
    {
        System.out.print(value + "~");
    }
}


2~4~9~30~-1~Vikrama
2~4~9~30~30~Vikrama
2~2~9~30~30~ikrama
2~2~9~30~22~ikrama
None of the above

Doubts

Problems

Topic: Java String substring() method - substring In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App