Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java What output is produced by the following code? int[ ][ ] testArray = new int[3][4]; for (int row = 0; row < testArray.length; row++)
Java
- 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:
- 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.
- 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.
- 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.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started