-
What is the output of this program?
public class arr_output
{
public static void main(String args[])
{
int arr_var [] = new int[20];
for (int j = 0; j < 20; ++j)
{
arr_var[j] = j;
System.out.print(arr_var[j] + " ");
j++;
}
}
}
-
- 0 2 4 6 8 10 12 14 16 18
- 2 4 6 8 10 12 14 16 18
- 2 4 6 8 10
- 0 2 4 6 8 10
- 0 1 2 3 4 5 6 7 8 9 10
Correct Option: A
When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 10 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop.
output: 0 2 4 6 8 10 12 14 16 18