This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: int count = 1; int sum = 0; int nextVal = 2; while (sum < LIMIT) { sum = sum + nextVal; nextVal = nextVal + 2; count = count + 1; } Trace this loop, that is, in the table next to the code, show values for variables nextVal, sum and count at each iteration. 7. Trace the loop and explain what is the output for the following loops: Loop Output i = 0; sum = 0; while(sum < 10) { i++; sum = sum + i; System.out.println(i + “ “ + sum); } Sum I 0 1 1 2 3 i = 0; sum = 0; while(sum < 10) { i++; sum = sum  i; System.out.println(i + “ “ + sum); } Sum i 0 1 13 2 i = 0; sum = 0; while(sum < 0) { i++; sum = sum  i; System.out.println(i + “ “ + sum); } false i = 0; sum = 0; while(sum >= 10) { i++; sum = sum + i; System.out.println(i + “ “ + sum); } false i = 0; sum = 0; while(sum < 10) ; { i++; sum = sum + i; System.out.println(i + “ “ + sum); } Terminate condition...
View
Full
Document
This note was uploaded on 12/07/2011 for the course BUS 350 taught by Professor Leighjin during the Fall '11 term at S.F. State.
 Fall '11
 LeighJin

Click to edit the document details