# Powers of Two Trace Ex Print powers of

• Slides: 33

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } N = 6 1

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n i 0 int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } N = 6 2

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n i v 0 1 int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } N = 6 3

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n i v i <= N 0 1 true int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } N = 6 4

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n i v i <= N 0 1 true 0 1 int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } N = 6 5

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 0 1 1 N = 6 6

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 0 1 N = 6 7

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 0 1 N = 6 8

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 0 1 1 2 N = 6 9

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 0 1 1 2 2 N = 6 10

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 0 1 1 2 N = 6 11

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 0 1 1 2 N = 6 12

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 0 1 1 2 2 4 N = 6 13

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 0 1 1 2 2 4 3 N = 6 14

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 0 1 1 2 2 4 N = 6 15

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 0 1 1 2 2 4 N = 6 16

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 0 1 2 3 1 2 4 8 N = 6 17

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 0 1 2 3 1 2 4 8 4 N = 6 18

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 0 1 2 3 1 2 4 8 N = 6 19

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 0 1 2 3 1 2 4 8 N = 6 20

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 0 1 2 3 4 1 2 4 8 16 N = 6 21

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 0 1 2 3 4 1 2 4 8 16 5 N = 6 22

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 0 1 2 3 4 1 2 4 8 16 N = 6 23

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 0 1 2 3 4 1 2 4 8 16 N = 6 24

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 0 1 2 3 4 5 1 2 4 8 16 32 N = 6 25

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 0 1 2 3 4 5 1 2 4 8 16 32 6 N = 6 26

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 0 1 2 3 4 5 1 2 4 8 16 32 N = 6 27

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 0 1 2 3 4 5 1 2 4 8 16 32 N = 6 28

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 0 1 2 3 4 5 6 1 2 4 8 16 32 64 N = 6 29

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 0 1 2 3 4 5 6 1 2 4 8 16 32 64 7 N = 6 30

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 0 1 2 3 4 5 6 1 2 4 8 16 32 64 N = 6 31

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 false 0 1 2 3 4 5 6 1 2 4 8 16 32 64 N = 6 32

Powers of Two: Trace Ex. Print powers of 2 that are 2 N. Increment i from 0 to N. Double v each time. n n int i = 0; int v = 1; while (i <= N) { System. out. println(i + " " + v); i = i + 1; v = 2 * v; } i v i <= N 0 1 true 1 2 true 2 4 true 3 8 true 4 16 true 5 32 true 6 64 true 7 128 false 0 1 2 3 4 5 6 1 2 4 8 16 32 64 N = 6 33