← Quiz: Java Strings: all 10 questions
Quiz: Java Strings · Question 6 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
String t = "Skills101";
System.out.println(t.indexOf('1') + " " + t.lastIndexOf('1'));
}
}
- A.7 9
- B.6 8
- C.6 6
- D.1 1
Answer & explanation
Correct answer: 6 8
Counting from 0: S k i l l s are indexes 0–5, so the first '1' is at 6 and the last at 8.
Can you get the rest right without peeking?
Take the timed Quiz: Java Strings quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →