1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tatyana61 [14]
2 years ago
9

3-Write a program in some language that has both static and stack dynamic local variables in subprograms. Create six large (at l

east 100 * 100) matrices in the subprogram—three static and three stack dynamic. Fill two of the static matrices and two of the stack-dynamic matrices with random numbers in the range of 1 to 100. The code in the subprogram must perform a large number of matrix multiplication operations on the static matrices and time the process. Then it must repeat this with the stack-dynamic matrices. Compare and explain the results. (at least 5 lines)
Computers and Technology
2 answers:
shutvik [7]2 years ago
7 0

Answer:

Check the explanation

Explanation:

Code:

****************************************

import java.util.Random;

public class Matrices {

static int staticMatrix1[][] = new int [100][100];

static int staticMatrix2[][] = new int [100][100];

static int staticMatrix3[][] = new int [100][100];

public void localMatrices() {

int localMatrix1[][] = new int [100][100];

int localMatrix2[][] = new int [100][100];

int localMatrix3[][] = new int [100][100];

Random r = new Random();

for(int i =0;i<100;i++) {

for(int j =0;j<100;j++) {

localMatrix1[i][j] = r.nextInt(100);

localMatrix2[i][j] = r.nextInt(100);

}

}

long localStart = System.nanoTime();

multiplyLocal(localMatrix1, localMatrix2);

long localEnd = System.nanoTime();

System.out.println("Time taken for local multiplication: "+ (localEnd-localStart)/ 1000000);

}

public void multiplyLocal(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{  

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

 

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void multiplyStatic(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{  

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

 

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void main(String args[]) {

Random r = new Random();

for(int i = 0;i<100;i++) {

for(int j = 0;j<100;j++) {

staticMatrix1[i][j] = r.nextInt(100);

staticMatrix2[i][j] = r.nextInt(100);

}

}

long staticStart = System.nanoTime();

multiplyStatic(staticMatrix1, staticMatrix2);

long staticEnd = System.nanoTime();

System.out.println("Time taken for static multiplication: "+ (staticEnd-staticStart)/ 1000000);

Matrices matrices = new Matrices();

matrices.localMatrices();

}

}

***************************************

Outputs:

Time taken for static multiplication: 6

Time taken for local multiplication: 12

******************************************

Sveta_85 [38]2 years ago
4 0

Answer:

See explaination

Explanation:

Code below:

import java.util.Random;

public class Matrices {

static int staticMatrix1[][] = new int [100][100];

static int staticMatrix2[][] = new int [100][100];

static int staticMatrix3[][] = new int [100][100];

public void localMatrices() {

int localMatrix1[][] = new int [100][100];

int localMatrix2[][] = new int [100][100];

int localMatrix3[][] = new int [100][100];

Random r = new Random();

for(int i =0;i<100;i++) {

for(int j =0;j<100;j++) {

localMatrix1[i][j] = r.nextInt(100);

localMatrix2[i][j] = r.nextInt(100);

}

}

long localStart = System.nanoTime();

multiplyLocal(localMatrix1, localMatrix2);

long localEnd = System.nanoTime();

System.out.println("Time taken for local multiplication: "+ (localEnd-localStart)/ 1000000);

}

public void multiplyLocal(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void multiplyStatic(int first[][],int second[][]) {

int[][] multiply = new int [100][100];

for (int c = 0; c < 100; c++)

{

for (int d = 0; d < 100; d++)

{

int sum = 0;

for (int k = 0; k < 100; k++)

{

sum = sum + first[c][k]*second[k][d];

}

multiply[c][d] = sum;

sum = 0;

}

}

}

public static void main(String args[]) {

Random r = new Random();

for(int i = 0;i<100;i++) {

for(int j = 0;j<100;j++) {

staticMatrix1[i][j] = r.nextInt(100);

staticMatrix2[i][j] = r.nextInt(100);

}

}

long staticStart = System.nanoTime();

multiplyStatic(staticMatrix1, staticMatrix2);

long staticEnd = System.nanoTime();

System.out.println("Time taken for static multiplication: "+ (staticEnd-staticStart)/ 1000000);

Matrices matrices = new Matrices();

matrices.localMatrices();

}

}

You might be interested in
Which of the following are pointers?
Pachacha [2.7K]

Answer:

Is there any options here

4 0
2 years ago
What is a sensitive compartmented information program
Dahasolnce [82]

Answer:

cpu

Explanation:

4 0
2 years ago
Assume that a kernel is launched with 1000 thread blocks each of which has 512 threads. If a variable is declared as a shared me
Alex

Answer:

The answer to this question is the option "B".  

Explanation:

In this question, the answer is option B which is 1,000 because the kernel is a central part of an operating system. kernel manages the computer and the hardware operations. most especially memory and CPU time. It also sheared a memory variable is allocated to thread blocks. That's why the answer to this question is 1,000.

7 0
2 years ago
Why did it take fewer 1-inch tiles than 1-centimeter tiles to measure the length of the cookie cutter?​
Romashka-Z-Leto [24]

The inch tiles are larger, meaning they use less space.

6 0
3 years ago
from january 2005 through july 2015, approximately how many electronic data records in the United States were breached, exposing
Brums [2.3K]
From January 2005 through July 2017, approximately 853 million electronic data records in the US were breached.
This allowed the attackers to take control over people's personal data, such as their various credit card numbers, and other important data, as well as their addresses, etc. The cyber police, as well as the regular police have been working hard to stop this from happening, but the hackers are very strong and smart.
4 0
3 years ago
Other questions:
  • ________ work(s) by using radio waves to communicate with radio antennas placed within adjacent geographic areas.
    8·1 answer
  • Janis is preparing a financial document. She needs to use the dollar symbol placed above the number key 4. Which key will Janis
    12·2 answers
  • What are the key goal, performance, and risk indicators?
    15·1 answer
  • To prevent unauthorized access and use, at a minimum a company should have a written __________ that outlines the activities for
    6·1 answer
  • You have to calculate the total amount you spent at the mall today. Which function should you use to do so?
    6·2 answers
  • Which statement is NOT CORRECT?
    11·1 answer
  • A message M is encapsulated by the TCP, IP and Ethernet protocols in that order as it travels down a protocol stack. What does t
    5·1 answer
  • Colin Mackay Inc., a software company with its head office in Amsterdam, has employees across three continents. Certain project
    11·1 answer
  • Two threads try to acquire the same resource at the same time and both are blocked. Then, they continually change their states i
    14·1 answer
  • How did you generate a random number for the user to guess?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!