Menu
Question Index
...

What will be the output of following program?

public class LastIndex {
    public static void main(String args[]) {
        String str = "You are best friend to me and to my sister";
        int last = str.lastIndexOf("to");
        int first = str.indexOf("to");
        System.out.print(first + "," + last);
    }
}


19,20
20,30
21,31
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