?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

IndexOf method

APCSA-DXDZGL

Consider the following code segment.

 String hi = "goodbye";
 int num = hi.indexOf("o");
 System.out.println(num);

What is printed as a result of executing the code segment?

A

-1

B

1

C

2

D

3

E

4