Question

In: Computer Science

Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with...

Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with random integers drawn from the range 1 to 100, and then output the index of the row with the highest sum along all the rows. To support your solution, create a class named RowSumThread.java from which you can instantiate Runnable objects, each of which will sum one row of the two-dimensional array and then place the sum of that row into the appropriate slot of a one-dimensional, 20-element array. To Summarize, your application will:

1. Generate the two-dimensional array of random integers

2. Start 20 concurrent threads, each of which places the sum of one row of the two-dimensional array into the corresponding slot of a one-dimensional array.

3. Onput the index of the row with the maximum value.

Solutions

Expert Solution

import java.util.*;
public class MaxRowSum {
public static void main(String[] args)
{
int total =0;
int temp = 0;
int index =0;
Random rand = new Random();
int[][] arr=new int[20][20];//20 row and 20 column 1. Generate the two-dimensional array of random integers
int[] sum = new int[20];
for(int i=0;i<20;i++)
{
total = 0;
for(int j=0;j<20;j++)
{
arr[i][j] = rand.nextInt(100) + 1; //generate randon no.between 1 to 100
total = total+arr[i][j];
}
sum[i] = total; //filled the sum matrix that carry the summation of row................2. Start 20 concurrent threads, each of which
} //places the sum of one row of the two-dimensional array into the corresponding slot of a one-dimensional array.
//System.out.println(Arrays.deepToString(arr));
for(int i=0;i<20;i++)
{
if(sum[i] > temp) { //condition to find largest row sum;
temp = sum[i];
index = i;
//System.out.println(index+" "+temp);
}
}
//System.out.println(Arrays.toString(sum));
System.out.println(index); //3. Onput the index of the row with the maximum value.
}
}


Related Solutions

Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with...
Create an application named MaxRowSum.java that instantiates a 20x20 two-dimentional array of integers, populates it with random integers drawn from the range 1 to 100, and then output the index of the row with the highest sum along all the rows. To support your solution, create a class named RowSumThread.java from which you can instantiate Runnable objects, each of which will sum one row of the two-dimensional array and then place the sum of that row into the appropriate slot of a one-dimensional, 20-element array. To Summarize, your application will: 1. Generate the two-dimensional array of random integers 2. Start 20 concurrent threads, each of which places the sum of one row of the two-dimensional array into the corresponding slot of a one-dimensional array. 3. Onput the index of the row with the maximum value.
Create an application containing an array that stores 5 integers. The application should call five methods...
Create an application containing an array that stores 5 integers. The application should call five methods from Array2 class that in turn (1) display all the integers, (2) display all the integers in reverse order, (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value. Save the file as ArrayTest.java.
Create the logic for an application that instantiates an object of the ATM class. Prompt the...
Create the logic for an application that instantiates an object of the ATM class. Prompt the user for the ATM object data to display the user’s bank balance PROGRAMMING LOGIC AND DESIGN QUESTION JAVA LANGUAGE
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
Java program In the main(), create and load a 2-dimentional array to hold the following sales...
Java program In the main(), create and load a 2-dimentional array to hold the following sales data Number of Tacos Sold (hard code the data into the array when you create it) Truck3 Truck4 .    Truck5 Monday 250 334 229 Wednesday   390 145 298 Friday .    434 285 . 156 • Write a method to calculate the grand total of all Tacos sold Write a method to allow the user to enter a truck number and get the total...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
Write an application that uses multithreading to compute the sum of the integers in an array...
Write an application that uses multithreading to compute the sum of the integers in an array of size 100,000. You can populate the array with random numbers and your application should display the sum. (JAVA)
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT