import java.util.concurrent.*; class MutableInteger { private int value; public int getValue(){ return value; } public void setValue(int value){ this.value = value; } } class Summation implements Runnable{ private int upper; private MutableInteger sumValue; public Summation(int upper, MutableInteger sumValue){ this.upper = upper; this.sumValue = sumValue; } public void run(){ int sum=0; for(int i=0;i<= upper; i++) sum += i; sumValue.setValue(sum); } } public class Driver{ public static void main(String[] args) { if(args.length>0){ if(Integer.parseInt(args[0])< 0) System.err.println(args[0]+"must be >=0."); else{// create the object to be shared MutableInteger sum=new MutableInteger(); int upper = Integer.parseInt(args[0]); Thread thrd = new Thread(new Summation(upper, sum)); thrd.start(); try{ thrd.join(); System.out.println("The sum of "+upper+" is "+sum.getValue()); } catch(InterruptedException ie) {} } } else System.err.println("Usage:Summation "); } }