adplus-dvertising
frame-decoration

Question

What is the output of the below Java program?
int balls[], rounds=3;
balls = new int[rounds];
for(int i=0; i<balls.length; i++)
 balls[i] = (i+1)*2;
for(int j=0; j<balls.length; j++)
 System.out.print(balls[j] + ",");

a.

0,2,4,

b.

1,2,3,

c.

2,4,6,

d.

Compiler error

Posted under Java Programming

Answer: (c).2,4,6,

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the below Java program?

Similar Questions

Discover Related MCQs

Q. Allocating memory with the keyword "new" causes the array elements to carry default values. State TRUE or FALSE.

Q. What is the default value of boolean data type elements of an array in Java?

Q. What is the default value of a char data type elements of an array in Java?

Q. What is the default value of float or double data type elements of an array in Java?

Q. What is the default value of byte, short, int or long data type elements of an array in Java?

Q. What is the default value of an element of Object type array?

Q. Lazy initialization of array requires the keyword "new" to allocate memory to the array and its elements. State TRUE or FALSE.

Q. Shorthand array initialization in Java needs the keyword "new" to allocate memory to the array and elements. State TRUE or FALSE.

Q. The name of an array variable or identifier can start with ___.

Q. An array in Java can be declared only of some predefined types. (TRUE/FALSE)

Q. If an index of an element is N, what is its actual position in the array?

Q. We should not specify the array size if declaration and initialization are done at the same time. (TRUE / FALSE)

Q. Which is the correct way of knowing Array Size in Java?

Q. In Java, an array can be declared without initialization without mentioning the size. (TRUE / FALSE)

Q. It is possible to skip initializing some elements of the array during Shorthand Initialization. (TRUE / FALSE)

Q. Which are the special symbols used to initialize an array at the time of the declaration itself?

Q. Which are the special symbols used to declare an array in Java?

Q. In Java language, an array index starts with ___.

Q. An array declaration in Java without initialization ___ memory.

Q. Unlike C-Arrays, the Java-Arrays have ___.