Menu
Question Index
...

What will be the output of following program?

public class Indexof {
    public static void main(String args[]) {
        String str = "You can also get the index strting from a specified position of the string.";
        int j = str.indexOf('n', 7);
        System.out.println("First occurance of char 'n' from 7th index :" + j);
        int m = str.indexOf("the", 21);
        System.out.println("First occurance of string \"the\" from 21th index :" + m);
    }
}


First occurance of char 'n' from 7th index :23
First occurance of string "the" from 21th index :64
First occurance of char 'n' from 7th index :22
First occurance of string "the" from 21th index :64
First occurance of char 'n' from 7th index :22
First occurance of string "the" from 21th index :65
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