Question discussion

What is the output of the following java program?public class Solution { public static void main(String[] args) { int[] p = {121, 201, 017}…

3283Medium DSSSB TGT Computer Science 0 replies 2 views
0

What is the output of the following java program?

public class Solution {
    public static void main(String[] args) {
        int[] p = {121, 201, 017};
        for (int j = 0; j < p.length; j++) {
            System.out.print(p[j] + " ");
        }
    }
}
  • A121 201 17
  • B121 201 15
  • CCompilation error
  • DRuntime error
Correct answer: B

Explanation

A leading 0 makes 017 an octal literal in Java, so 017 = 15. The program prints 121 201 15 followed by a space.

Discussion 0

Nobody has replied yet. Start the discussion!