| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice Test
Share
easy Solved by 8 students
String indexOf Method
< Prev
Next >

Which line of code correctly finds the starting index of the substring “Java” in the given sentence?

public class SubStringSearch {
    public static void main(String[] args) {
        String sentence = "I love programming in Java";
        // Missing line: Save the index of "Java" in variable 'index'
        System.out.println("Index: " + index);
    }
}
A

int index = sentence.indexOf(“Java”);

B

int index = sentence.indexOf(“programming”);

C

int index = sentence.indexOf(“java”);

D

int index = sentence.indexOf(“in Java”);

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2cphong200911 0m 30s 70
#3lsj0803092211 1m 37s 3
#4richa.tuli01 1m 30s -100
#5y.seong202712 4m 33s -183
#6jeonsaw172311 16m 03s -863
APFIVE © 2020.
Email: [email protected]|Privacy Policy