Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
Java - Strings and String Handling
What is the output of this code?
String s = "Hello";
System.out.println(s.charAt(1));
AH
Be
Cl
Do
Step-by-Step Solution
Solution:
  1. Step 1: Understand charAt() indexing

    charAt(1) returns the character at index 1 (second character).
  2. Step 2: Identify character at index 1 in "Hello"

    Index 0 = 'H', index 1 = 'e'.
  3. Final Answer:

    e -> Option B
  4. Quick Check:

    charAt(1) = 'e' [OK]
Quick Trick: Indexing starts at 0; charAt(1) is second character [OK]
Common Mistakes:
  • Confusing index 1 with 0
  • Expecting first character instead of second

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes