# Nt[] num = new int[100]; for (int i = 0; i < 50; i++)num[i] = i; num[5] = 10; num[55] = 100; what

Nt[] num = new int[100]; for (int i = 0; i < 50; i++)num[i] = i; num[5] = 10; num[55] = 100; what is the value of num. length in the array above? 1. 02. 1003. 994. 101

## This Post Has 3 Comments

1. derisepicowe0fa says:

Option 2. 100 is correct.

Explanation:

In the above example,  we have assigned the value 100 to the array num[] while creating the object of that array.

In the next line, we are assigning the values to the array num[] through the loop which will be executed till less than 50 values as it will be started from 0 but in the next line from that we are getting the total number of elements of that array which will be 100 because length function is used to get the total number of elements in the array which is already assigned as 100.

2. cjjohnson1221 says:

1. 99

Explanation:

As the array is declared with space of 100 integers, 100 integers' space will  be allocated to variable num. Moreover, Index number of last component is always the length - 1 because array's  index start with 0 and ends till length-1. As array will initialize all the remaining spaces with garbage value so they will be displayed if accessed through num[index] where index s the index number to be displayed.

As size of array is 100. So, 99 will be the index of the last component of the array.

3. ajaydonlee says:

Option 2: 100

Explanation:

The given code is regarding a Java array. To create an array in Java, the syntax is as follows:

type [] arrayname = new type[size]

In Java, this is possible to set a size for an array by giving an integer within the bracket. For example, int [] num = new int[100] will set the array size 100 for num . This means the num  can hold 100 components within the array.

Once the size is set for an array, the size cannot be changed in later stage.