🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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'));
    }
}
  1. A.7 9
  2. B.6 8
  3. C.6 6
  4. 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 →