Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. :)

image text in transcribed

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 Programming Task: You will implement a multithreaded program for matrix multiplication. Your program will calculate each element Rij of the matrix product R of two matrices P and Q in a separate thread. So, the number of threads is equal to the number of terms in the matrix R. Use either Pthreads or Java threads to implement this program. The matrices to be multiplied are: P=16 5 andQ=15 63 4 0 98

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

=+Have they changed the way employees view IP?

Answered: 1 week ago