public static void main(String[] args) {
//Given the following code :
int[][] array2D = {{3, 4, 5, 1}, {3,6,1,2}, {1,3,6,5};
Answer :
1- All values of array2D are automatically 0 ? Yes or No
2- What is the value of array2D [3] .length ?________
3- The value that array2D.length shows is 12: Yes or No ?
4- Assign the value of 12 to the element in the third row, fourth column :
5- the value obtained when calculating array2D [1] [1] + array2D [2] [3] is?
Solution 1:
No. Because array2D array is already specified
with elements.
Solution 2:
For array2D[3].length will give you ArrayIndexOutOfBoundException. Because array is of length of three, it will starts from zero index, so the highest index will be two.
Solution 3:
No, the length is 3.
length to determine the number of rows in a 2D array because the length of a 2D array is equal to the number of rows it has.
Solution 4:
public class Main
{
public static void main(String[] args) {
int[][] array2D = {{3, 4, 5, 1},
{3,6,1,2}, {1,3,6,5}};
array2D[2][3]=12;
System.out.println(array2D[2][3]);
}
}
Solution 5:
The value is 18.
public class Main
{
public static void main(String[] args) {
int[][] array2D = {{3, 4, 5, 1},
{3,6,1,2}, {1,3,6,5}};
array2D[2][3]=12;
System.out.println(array2D [1] [1]
+ array2D [2] [3]);
}
}
Get Answers For Free
Most questions answered within 1 hours.