Thread: hay
View Single Post
Old Mar 2nd, 2008, 10:33 PM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: hay

Please use CODE tags next time.

You need to re-initialize x inside the for loop. The last zero read in is preventing the while loop from executing:
(also initialize total if it's meant to be for each box)

java Syntax (Toggle Plain Text)
  1. int x=1;
  2. int total=0;
  3. int t1=0;
  4. for(int j=0;j<3;j++){
  5. System.out.println("Box 00"+(j+1)+"");
  6. x = 1;
  7. total = 0; //re-initialize the individual box total
  8. while(x!=0){
  9. System.out.print("Input egg wegiht ");
  10. x=input.nextInt();
  11. total=total+x;
  12.  
  13. }
  14. System.out.println("Total wegiht of the box : "+total);
  15. System.out.println();
  16. t1=total+t1;
  17. }
  18.  
  19. System.out.println("Grand Total :" +t1);
  20. }
  21. }
OpenLoop is offline   Reply With Quote