Knowee
Questions
Features
Study Tools

What is output of the following code:public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }

Question

What is output of the following code:public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the code will be:

120 200 14

Explanation:

The code is written in Java. It declares an array of integers with three elements: 120, 200, and 016.

The third element, 016, is an octal number (base 8) because it starts with a 0. In decimal form (base 10), 016 is equal to 14.

The for loop iterates over each element in the array and prints it out, resulting in the output: 120 200 14.

This problem has been solved

Similar Questions

What is the output of the following code :class MyClass {public static void main(String[] args) {int i=1,j=1;for (;i<3;i++){for(;j<4;j++);j++;System.out.print(i + j+" ");}}

What is output of the following code:public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }}120 200 16120 200 14120 200 016016 is a compile error. It should be written as 16.

Determine output:public class Test{ public static void main(String[] args){ int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for(int i = 0; i < x.length; i++) System.out.print(y[i] + " "); }}

public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); }}

What is the result of compiling and running the following code?public class Test{ public static void main(String[] args){ int[] a = new int[0]; System.out.print(a.length); }}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.