What will be the output of the following program? public class Demo { public…

2024

What will be the output of the following program? public class Demo { public static void main(String[] args) { int[] arr = {120, 200, 016}; for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } } }

Answer: A. 120 200 14Step 1: The array contains three integers: 120, 200, and 016. Step 2: In Java, a number with a leading 0 is treated as an octal literal (base 8). Step 3: The…

  1. A.

    120 200 14

  2. B.

    120 200 016

  3. C.

    Compilation Error

  4. D.

    120 200 16

  5. E.

    Question not attempted

Attempted by 305 students.

Show answer & explanation

Correct answer: A

Step 1: The array contains three integers: 120, 200, and 016.

Step 2: In Java, a number with a leading 0 is treated as an octal literal (base 8).

Step 3: The value 016 in octal means: 1×8¹ + 6×8⁰ = 8 + 6 = 14 in decimal.

Step 4: The loop prints each element in decimal form: 120, 200, and 14.

Step 5: The output is: 120 200 14.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…