Menu
Topics Index
...
`

Flowers2494


If you need explanation Read this topic

If you need Answer Take test on this topic

Flowers2494
What will be the output of the following program?
public class Flowers {
    public static void main(String[] args) {
        String strName;
        int number;
        strName = "Rose";
        number = strName.indexOf("rose");
        System.out.println("Output is " + number);
    }
}

A. Output is 0
B. Output is 1
C. Output is 4
D. Output is -1
E. Compilation Error or Runtime Error
Topic: Java Searching Strings - Java indexOf, lastIndexOf Methods

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is D...bcz Returns the index within this string of the first occurrence of the specified substring. If it does not occur as a substring, -1 is returned.

Posted by Anvesh Athmakuri    2014-03-17 12:35:28


Ans is D since rose is not matched with Rose in the strName it returns  -1 in the number

Posted by Bharath Yelchuri    2014-03-17 12:39:19


ans is D because Rose is not identified in given argument "rose" so it returns -1

Posted by Vivek Roshan    2014-03-17 12:39:59


answer is E... :D

Posted by Akhil Goutham Kotini    2014-03-17 13:42:25


Ans: D. IndexOf method is used to retrieve the position of characters only. so it will return -1 for the strings.

Posted by Chandu Chandrahas    2014-03-18 02:41:54


Congratulations Anvesh Athmakuri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-18 04:12:56


© meritcampus 2019

All Rights Reserved.

Open In App