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
Mille gets a text from her friend asking if she wants to come over. It seems like a bit of a hassle to go to her friend's house,
Licemer1 [7]

Answer:

OC. It will be a more positive experience if she spends time with her friend in person.

Explanation:

You should always spend time with people in person rather than online whenever you get the chance.

8 0
1 year ago
To create a datetime object for the current date and time, you can use theGroup of answer choicestoday() method of the date clas
SVEN [57.7K]

var theDate = new DateTime (DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, hours, minute, second);

6 0
2 years ago
The source must decode a message before it can be sent. select one: <br> a. True <br> b. False
Pani-rosa [81]
True because that's what i said it is 
5 0
3 years ago
Where in the Formula tab on the ribbon would you find the Use in Formula function?
Leviafan [203]

Answer:

In Function library you would find the use in Formula function

5 0
3 years ago
Read 2 more answers
Nicole wants to create a database to collect information about videos in her video rental store. She would like to use the datab
kobusy [5.1K]

Answer:

All the field which she has mention has to created by Nichole in her database.

Explanation:

The following fields have to be created in the database

title, rating, actor, and producer rating, director, and actor title, rating, actor 1, actor 2, actor 2, actor 4, producer, and in the stock product number, price, and rating

 

And additional field also has to create movie-length also as integer field which should carry the length of the movie  

Date of release and movie certificate also can be captured so the search engine will be very useful

3 0
3 years ago
Other questions:
  • What kind of testing is basically checking whether a game or feature works as expected by the developers?
    10·1 answer
  • What do you call a named collection of data stored on a disk?
    15·1 answer
  • Your company received a call from a historical society inquiring about the possibility of networking a two-century-old building
    15·1 answer
  • I love science its my favorite subject
    13·2 answers
  • Please solve the ones you can. Solving Both will be appreciated. thank you
    13·1 answer
  • Differentiate between refraction of light and reflection of light
    8·2 answers
  • Film’s importance in today’s economy?
    12·1 answer
  • Who has more Tanks? Russia or USA? You get ti right and you get BRAINLIEST
    12·2 answers
  • Which actions represent parody?
    5·1 answer
  • A web site that contains large numbers of misspelled words and grammatical errors fails which of these general criteria?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!