CS 111 - 9/29/30 Exam 1 - On Thursday 10/1/15 20 Multiple Choice "What is the value in z when the following code finishes executing?" 3 pts each ==> 60 pts total for this section 2 Write Code Questions 20 pts each ==> 40 pts total for this section Q 21. Write code to do X using Turtles public static void main (String[] args) { Q 22. Write a method to do X using Turtles and a loop public static void drawOctagon (Turtle t, int length, int thickness) { ========================================= x = 1; y = 2; z = 3; while (x <= 4) { z = z + y; y = y * 2; x = x + 1; } x: 1 2 3 4 5 y: 2 4 8 16 32 z: 3 5 9 17 33 =========================== x = 5; z = 0; while (x > 0) // careful this one is tricky { z = z + x; x = x - 1; // counting down not up! } x: 5 4 3 2 1 0 z: 0 5 9 12 14 15 ================================== x = 5; z = 0; while (x < 0) // careful this one is tricky { z = z + x; x = x - 1; // counting down not up! } x: 5 z: 0 ================================== x = 5; z = 0; while (x > 0) // careful this one is tricky { z = z + x; x = x + 1; // counting down not up! } A. 15 B. 14 C. 30 D. 276 E. None of the above because an infinite loop occcurred ======================================== x = 0; y = 2; z = 2; while (x < 8) // NOTE: using < NOT <= { z = x + y + z; x = x + 2; // NOTE: Increment by 2 } x: 0 2 4 6 8 y: 2 z: 2 4 8 14 22 =========================== j = 0; x = 1; y = 2; z =3 while (j < 5) { z= x + y+ z; y = x + y; x = x + 1; } j: 0 x: 1 y: 2 z: 3 ============================ x = 2; y = 4; z = 6; while ( x <= 3 ) { z = x + y; y = x + z; x = x + x; } x: 2 4 y:4 8 z:6 6