Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain why the following program prints different totals for the given array. Rewrite it so that this does not happen. class ShowInterf { public static

Explain why the following program prints different totals for the given array. Rewrite it so that this does not happen.

class ShowInterf { public static void main(String args[]) { int[] b = { 23, 45, 33, 13, 28, 45, 34, 54, 67 }; (new Thread(new Summer(b))).start(); (new Thread(new Swapper(b))).start(); } } class Swapper implements Runnable { int b[]; public Swapper(int k[]) { b = k; } public void run() { int j, k, t; while (true) { j = (int)(Math.random() * b.length); k = (int)(Math.random() * b.length); t = b[j]; b[j] = b[k]; b[k] = t; } } class Summer implements Runnable { int b[]; public Summer(int k[]) { b = k; } public void run() { while (true) { int total = 0; for (int i = 0; i < b.length; i++) total += b[i]; System.out.println(total); } } }

Update: This is the full question that was provided. Further basic knowledge is not known.

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

Modeling Communication

Answered: 1 week ago