Multi-D Array Practical

Advertisements
Advertisements
Advertisements3
Advertisements4
Advertisements6
Advertisements66

1. What is the purpose of the following java code?

int[][] arr = new int[3][4];

Ans. It creates a two- dimensional array with 3 rows and 4 columns.

2. What is the output of the following Java code?

int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length; j++) {

System.out.print(arr[i][j] + ” “);

}

System.out.println();

}

Ans. 1  2  3  4  5  6  7  8  9.

3. What is the output of the following Java code?

int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

int sum = 0;

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length; j++) {

sum += arr[i][j];

}

}

System.out.println(sum);

Ans. 45.

Author: Lakshmi Prasanna Ponnala

Completed M.Tech in Digital Electronics and Communication Systems.

Leave a Reply

error: Content is protected !!

Discover more from ece4uplp

Subscribe now to keep reading and get access to the full archive.

Continue reading