Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Whats wrong with my code? In the output, the index never changes, its always 0. The highest sum number always ends in a 0, like

Whats wrong with my code?

In the output, the index never changes, its always 0. The highest sum number always ends in a 0, like the numbers generating arent truly random between 1-100. And i feel like the sums are kind of low.

*** I am not looking for a whole new code, just someone to point out some if there are any logical issues and what line, what i can do to fix it***

the problem:

image text in transcribed

My code:

import java.util.Random;

public class MaxRowSum extends Thread{

Random rand = new Random(); int arr[][] = new int [20][20]; // creats 2D array 20x20 int sumArr[] = new int [20]; // creates 1D array to store each row's sum int highest = 0; // which is the highest sum int indexOfHighest = 0; int randomNum = rand.nextInt(50)+1; // populate 2D array with random numbers public void run(){ for (int i=0; i

for (int row=0; rowhighest){ highest = rowSum; // highest sum will = rowSum if rowSum is greater than previous highest indexOfHighest=row; // set the index of the highest sum to the row that corresponds in the 2D array } } System.out.println("Highest sum is: "+highest+" ...found in row index "+indexOfHighest); } // end run

} // end class

-----------------------------------------------------

import java.io.*;

public class RowSumThread{

public static void main(String[] args){ MaxRowSum[] thread = new MaxRowSum[20]; for(int i=0; i

}

my output:

image text in transcribed

Problem 1: Create a PrintChar class that extends Thread. The constructor should accept a character and an integer as parameters. The run method should print the character the number of times indicated by the integer. Create an application named CharApp.java that instantiates two PrintChar objecs, one passed "A" and 200 and the other one passed "B" and 200. It then instantiates and starts two thread objects. Experiment with the resulting system, using different numerical parameters for PrintChar objects. Create a report (a text file printChar.txt) about the results of vour experiments-explain how the multiple threads work in vour program Problem 2: 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

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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions