Question: Given the JAVA code below, 1. Run the code and use it to calculate sum from 1-N, ( try N =100000000). 2. Measure the time

Given the JAVA code below, 1. Run the code and use it to calculate sum from 1-N, ( try N =100000000). 2. Measure the time taken of the programs to calculate this sum. And print it. 3. Modify the code to have two threads, one will calculate sum from 1 to N/2 and the second will Calculate sum from N/2 +1 to N. In the main method, add the two partial sums and display the result. 4. Measure the time taken of the new program and compare it to what you had in 2.Given the JAVA code below, 1. Run the code and use itto calculate sum from 1-N, ( try N =100000000). 2. Measure thetime taken of the programs to calculate this sum. And print it.

Given the JAVA code below, 1. Run the code and use it to calculate sum from 1-N, (try N=100000000). 2. Measure the time taken of the programs to calculate this sum. And print it. 3. Modify the code to have two threads, one will calculate sum from 1 to N/2 and the second will Calculate sum from N/2 +1 to N. In the main method, add the two partial sums and display the result 4. Measure the time taken of the new program and compare it to what you had in 2. You may use any Java library to help you get it done. class Sum { private int sum; public int getSum() { return sum; } public void set Sum(int sum) { this.sum = sum; } } class Summation implements Runnable { private int upper; private Sum sumValue; public Summation (int upper, Sum sumValue) { this.upper = upper; this.sumvalue sumValue; } public void run() { int sum = 0; for (int i = 0; i 0) { if (Integer.parseInt (args[0]) = 0."); else { Sum sumobject = new Sum(); int upper = Integer.parseInt(args[0]); Thread thrd = new Thread (new Summation (upper, sumobject)); thrd.start(); try { thrd.join(); System.out.println ("The sum of "+uppert" is " +sumObject.getSum()); } catch (InterruptedException ie) {} } } else System.err.println("Usage: Summation "); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this task well need to complete the following steps Run the original code and measure ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!