39.3k views
0 votes
Which of the following initializer lists would correctly set the elements of array n?

a. int[] n = { 1, 2, 3, 4, 5 };.
b. array n[ int ] = { 1, 2, 3, 4, 5 };.
c. int n[ 5 ] = { 1; 2; 3; 4; 5 };.
d. int n = new int( 1, 2, 3, 4, 5 );.

1 Answer

6 votes

Answer:

The correct answer to this question is option (a).

Explanation:

In the programming language (java) the syntax for declaring,initializing single denominational array can be given as:

Syntax:

datatype array[] arrayname; // declare the array

Example: int [] a;

a = new int[5]; // create the array

int [] n ={2,5,7,9,3}; // initialize all elements

Or

a[0] = 2;

a[1] = 22;

a[2] = 12;

a[3] = 20;

a[4] = 23;

In the above we define the way to initialize the array. So the correct way to set array element is option (a).

User TudorIftimie
by
4.3k points