157k views
2 votes
Which of the following statements represents the number of columns in a regular two-dimensional array named values?

A) values[0].length
B) values.length
C) values.length)
D) values[0].length0
E) values.getColumnLength0)

User Nitu Dhaka
by
2.8k points

1 Answer

5 votes

Answer:

(a) values[0].length

Step-by-step explanation:

In programming languages such as Java, an array is a collection of data of the same type. For example, a and b below are an example of an array.

a = {5, 6, 7, 9}

b = {{2,3,4}, {3,5,4}, {6,8,5}, {1,4,6}}

But while a is a one-dimensional array, b is a regular two-dimensional array. A two-dimensional array is typically an array of one-dimensional arrays.

Now, a few thing to note about a two-dimensional array:

(i) The number of rows in a 2-dimensional array is given by;

arrayname.length

For example, to get the number of rows in array b above, we simply write;

b.length which will give 4

(ii) The number of columns in a 2-dimensional array is given by;

arrayname[0].length

This is with an assumption that all rows have same number of columns.

To get the number of columns in array b above, we simply write;

b[0].length which will give 3

Therefore, for a regular two-dimensional array named values, the number of columns is represented by: values[0].length

User Kartik Sharma
by
3.9k points