write a java program named matrix.java that multiplies 2 matrices.( write alot o
ID: 3745220 • Letter: W
Question
write a java program named matrix.java that multiplies 2 matrices.( write alot of comments explaining please , I'm also comparing with my own code)
1. The program should prompt the user for the dimensions of the two matrices, making sure that the user input is greater than or equal to 50.
2. If the above is not met, prompt the user for a new value.
3. Now generate random integer numbers (ranging from 1 to 99) to fill both matrices.
4. Display these two matrices on the screen.
5. Multiply the two matrices and display the result on the screen.
6. Insert a clock to see how long it would take to multiply these two matrices and display the time (with a message to this effect).
7. Prompt the user asking if they want to repeat the program.
Explanation / Answer
import java.util.Random; import java.util.Scanner; public class matrix { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random random = new Random(); String choice; int size, sum; int[][] A, B, C; while (true) { while (true) { System.out.print("Enter size of matrix[>=50]: "); size = in.nextInt(); if(size >= 50) break; System.out.println("Error. Enter size greater than or equal to 50"); } A = new int[size][size]; B = new int[size][size]; C = new int[size][size]; long startTime = System.currentTimeMillis(); for(int i =0 ; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.