I'm trying to write a program that prints a randomly generated matrix and a transposed matrix, but I can't quite figure it out. When I attempt to compile I get the error on line 41 "error: cannot find symbol printMatrix(transposedMatrix); ^ I've worked on this for a few hours now and can't figure it out, thanks in advance for the help.
I apologize if the formatting for this code is a little off, it looks fine in Sublime and I'm not not used to this site.
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int rows = 0;
int cols = 0;
while (rows < 1 || rows > 10) {
System.out.print("Enter the number of rows (1-10): ");
int userRows = input.nextInt();
if (userRows < 1 || userRows > 10) {
System.out.println("ERROR! The number of rows cannot be outside the specified range of 1-10!");
}
else userRows += rows;
}
while (cols < 1 || cols > 10) {
System.out.print("Enter the number of columns (1-10): ");
int userCols = input.nextInt();
if (userCols < 1 || userCols > 10) {
System.out.println("ERROR! The number of columns cannot be outside the speified range of 1-10!");
}
else userCols += cols;
}
int[][] originalMatrix = new int[rows][cols];
for (int row = 0; row < originalMatrix.length; row++)
for (int col = 0; col < originalMatrix[row].length; col++) {
originalMatrix[row][col] = (int) (Math.random() * 1000);
}
System.out.println("\nOriginal matrix:");
printMatrix(originalMatrix);
System.out.println("\nTransposed matrix:");
printMatrix(transposedMatrix);
}
public static void printMatrix(int[][] matrix) {
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
System.out.print(matrix[row][col] + " ");
}
System.out.println();
}
}
public static int[][] transposedMatrix(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
int[][] transposedMatrix = new int[n][m];
for(int x = 0; x < n; x++) {
for(int y = 0; y < m; y++) {
transposedMatrix[x][y] = matrix[y][x];
}
}
return transposedMatrix;
}
}