Java Program: In main () construct a two-dimensional \"square\" array with 3 row
ID: 3769836 • Letter: J
Question
Java Program:
In main () construct a two-dimensional "square" array with 3 rows and 3 columns named i Nums. This is commonly called a square matrix transposition algorithm; you may need to research this a bit. Write and call the method fvPop () to populate it with the random integers between 0 and 9, inclusive. Write and call the method f vDisplay () to display it. Write a method f vTranspose () which will transpose the values in the matric. Sample output (color and borders added for conceptual purposes only; simply output your values with print f). When you get your solution working with a square matrix of 3, then modify your code so that will allow you to handle any size square matrix in your transpose method. In other words, use the length property.Explanation / Answer
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
//create the grid
final int rowWidth = 9;
final int colHeight = 9;
Random rand = new Random();
int [][] board = new int [rowWidth][colHeight];
//fill the grid
for (int row = 0; row < board.length; row++) {
for (int col = 0; col < board[row].length; col++) {
board[row][col] = rand.nextInt(10);
}
}
//display output
for(int i = 0; i < board.length; i++) {
for(int j = 0; j < board[i].length; j++) {
System.out.print(board[i][j] + " ");
//System.out.println();
}
System.out.println();
}
} //end of main
} //end of class Main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.