Question: Java What output is produced by the following code? int[ ][ ] testArray = new int[3][4]; for (int row = 0; row < testArray.length; row++)

Java
  1. What output is produced by the following code?

int[ ][ ] testArray = new int[3][4]; for (int row = 0; row < testArray.length; row++) for (int col = 0; col < testArray[row].length; col++) testArray[row][col] = col; for (int row = 0; row < testArray.length; row++) { for (int col = 0; col < testArray[row].length; col++) System.out.print(testArray[row][col] + " "); System.out.println(); }

2. Write code that will fill the following array a with numbers typed at the keyboard:

int [ ][ ] a = new int[4][5];

3. Write Java programs for following:

  1. To create a 2D array to store numbers. Take the input of the array. Display the contents of the array in the matrix form. Find and display the sum of all elements, sum of all even numbers, and sum of all odd numbers.
  2. To create two 2D arrays and carry out the following operations: sum of the two matrices and difference of the two matrices. Display the matrices in a proper matrix format using a method.
  3. To create a matrix of size of MXN, find the sum of each row, sum of each column and if it is a square matrix then find the sum of diagonal elements also. M and N are user input.
  4. To create a square matrix of order 3x3 containing integers, using a method CREATE( ). The program should then use a function SWAP( ) which swaps two integer values, to find the transpose of the matrix, and display the transpose using a function DISPLAY( ).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!