variable i declared at line 16? variable k declared at line 7? variable k declar
ID: 3551464 • Letter: V
Question
variable i declared at line
16?
variable k declared at line
7?
variable k declared at line
26?
program. What is the final output? Keep in mind the
scopes of the variables while making your trace table. How
many columns will it need? (Trace the program first, then
type it into Eclipse to verify your answer).
public class WhatzitRevisited { public static void main(String[] args) { int i = 50; int j = 0; while (i > 0) { int k = whatzitTheFirst(i); j = j + k; i = i / 10; System.out.println("Main Loop"); } System.out.println("The final value is: "+j); } private static int whatzitTheFirst(int j) { int i = 50; int k = 5; while (k < j) { System.out.println("First Whatzit"); i = i - whatzitTheSecond(j); k = k*10; } return i; } private static int whatzitTheSecond(int k) { int j = 2; int i = 0; while (j > 0) { System.out.println("Second Whatzit"); i = i + k; j = j - 1; } return i; } }
Explanation / Answer
- Line to 23 are in scope with i
- Line 7 to 10
- Line 26 to 34 (method argument, valid for through out method definition)
-
output :
The final value is: 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.