Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Explain each component in the following code how you usually would with comments) import java.util.Random; import java.util.Scanner; public class matrix { public static void main(String[]

(Explain each component in the following code how you usually would with comments)

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 ; i < size; ++i) { for(int j =0 ; j < size; ++j) { A[i][j] = 1 + random.nextInt(99); B[i][j] = 1 + random.nextInt(99); sum = 0; for(int k = 0; k < size; ++k) { sum += A[i][k] * B[k][j]; } C[i][j] = sum; } } System.out.println("Matrix A"); for(int i = 0; i < size; ++i) { for(int j = 0; j < size; ++j) { System.out.printf("%3d ", A[i][j]); } System.out.println(); } System.out.println("Matrix B"); for(int i = 0; i < size; ++i) { for(int j = 0; j < size; ++j) { System.out.printf("%3d ", B[i][j]); } System.out.println(); } System.out.println("Matrix A * B"); for(int i = 0; i < size; ++i) { for(int j = 0; j < size; ++j) { System.out.printf("%6d ", C[i][j]); } System.out.println(); } long endTime = System.currentTimeMillis(); System.out.println("It took " + (endTime-startTime) + " milliseconds"); System.out.print("Do you want to try again(y or n)? "); choice = in.next(); if(choice.equalsIgnoreCase("n")) break; } }

}

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago

Question

=+j Improve the effectiveness of global and virtual teams.

Answered: 1 week ago