Ya it works and thank you very much for that
another thing as i know for loop doing rept what it got inside so i thought by puting while loop inside for loop it will repet until the for loops condition "yes"
is that because when we hit "0"and stop the while loop then the compiler takes x value as "0" for the hole program
Quote:
Originally Posted by OpenLoop
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)
int x=1; int total=0; int t1=0; for(int j=0;j<3;j++){ System.out.println("Box 00"+(j+1)+""); x = 1; total = 0; //re-initialize the individual box total while(x!=0){ System.out.print("Input egg wegiht "); x=input.nextInt(); total=total+x; } System.out.println("Total wegiht of the box : "+total); System.out.println(); t1=total+t1; } System.out.println("Grand Total :" +t1); } }
|