Question discussion

What is the output of the following Java program?public class Main { public static void main(String[] args) { String s = "Hello"; System.ou…

1504Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        String s = "Hello";
        System.out.println(s.substring(1, 3) + s.charAt(4));
    }
}
  • Aelo
  • Bell
  • Cello
  • DHel
Correct answer: A

Explanation

substring(1, 3) gives "el" and charAt(4) is 'o', so the output is "elo".

Discussion 0

Nobody has replied yet. Start the discussion!