Multiple choice

What would be the value of i and ch after the execution of the following statements in Java? int i; char ch; String st1=”Rakesh Roshan”; i=st1.indexOf(‘e’); ch=st1.charAt(5);

  1. The value of i will be 4 and the value of ch will be ’s’.

  2. The value of i will be 3 and the value of ch will be ’h’.

  3. The value of i will be 3 and the value of ch will be ’s’.

  4. The value of i will be 4 and the value of ch will be ’h’.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The index of character ‘e’ is 3 because the index is starting from 0. The character at position 5 is ‘h'.