?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

String indexOf and substring Methods Within One Statement

APCSA-NGPVXX

Consider the following code segment.

// there are single spaces between each word in state
String state = "Mississippi is a southern state";
int a = state.substring(state.indexOf("p")).indexOf(state.substring(state.indexOf("i"),3));
System.out.print(a);

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

A

1

B

4

C

7

D

8

E

12