Write a Java program as follows. a. Declare integer 2D array with 5 rows and 5 c
ID: 3908522 • Letter: W
Question
Write a Java program as follows.
a. Declare integer 2D array with 5 rows and 5 columns.
b. Initialize the array elements to random integers between 1 and 9.
c. Perform the tasks given below. i. Display all the elements in the 2D array as a table of rows and columns.
ii. Display all the diagonal elements (the elements where row index and column index are same)
iii. Find the minimum of the first row.
iv. Find the maximum of the third column.
Use following statement to get the integer random numbers between 1 - 9. int r = (int) (Math.random()*(9-1+1)) + 1;
Explanation / Answer
import java.util.Random; public class RandomMatrix { public static void main(String[] args) { // a. Declare integer 2D array with 5 rows and 5 columns. int[][] arr = new int[5][5]; // b. Initialize the array elements to random integers between 1 and 9. Random random = new Random(); for(int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.