Question
Hi, I finished the program, but I'm trying to get it to where of instead of prompting the user to input the length of the
Hi, I finished the program, but I'm trying to get it to where of instead of prompting the user to input the length of the rows and columns of the matrices, I trying to get the numbers shown in the example to be stored in the array and do all the calculations (without user's input). I'll leave my code below for remodifications, and it also needs comments explaning what is going on in the code. Thanks. :)
package prog1_4103;
import java.util.*;
//class to implement thread to calculate matrix product class MatProd extends Thread {
int[][] a; int[][] b; int[][] c; int rnge, col; int dm; public MatProd(int[][] a, int[][] b, int[][] c, int rg, int colm, int dm_cm){ this.a=a; this.b=b; this.c=c; this.rnge=rg; this.col=colm; this.dm=dm_cm; } //This runs the method to calculate every element of result matrix R public void run() { for(int i=0; i //this is where the main class calls and initiates mitrices a and b. public class MatMult{ /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner Input = new Scanner(System.in); System.out.print("Enter the number of rows and columns for Matrix A respectively: "); int rowA = Input.nextInt(); int colA = Input.nextInt(); //edit //System.out.print("Enter the number of columns of Matrix A: "); //int colA = Input.nextInt(); System.out.print("Enter the number of rows and columns for Matrix B respectively: "); int rowB = Input.nextInt(); int colB = Input.nextInt(); //edit //System.out.print("Enter the number of columns of Matrix B: "); //int colB = Input.nextInt(); System.out.println(); if(colA!=rowB) { System.out.println("Sorry, but the input for this Matrix Product is invalid. Please try again."); System.exit(-1); } System.out.println(); int[][] A = new int[rowA][colA]; int[][] B = new int[rowB][colB]; int[][] C = new int[rowA][colB]; MatProd[][] third = new MatProd[rowA][colB]; System.out.println("Implement Matrix A"); System.out.println(); //read Matrix A from user. for(int i=0; i
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