1 powers of two: trace ex. print powers of 2 that are 2 n. increment i from 0 to n. double v each...

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

Upload: rosa-maurice

Post on 01-Apr-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

1

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

N = 6

Page 2: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

2

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0

i

N = 6

Page 3: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

3

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 1

i v

N = 6

Page 4: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

4

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 1

i v

true

i <= N

N = 6

Page 5: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

5

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 10 1

i v

true

i <= N

N = 6

Page 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. int i = 0; int v = 1; while (i

6

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 10 1

i v

1

true

i <= N

N = 6

Page 7: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

7

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 10 1

i v

1 2

true

i <= N

N = 6

Page 8: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

8

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 10 1

i v

1 2

true

i <= N

true

N = 6

Page 9: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

9

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 2

0 1

i v

1 2

true

i <= N

true

N = 6

Page 10: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

10

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 2

0 1

i v

1 2

2

true

i <= N

true

N = 6

Page 11: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

11

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 2

0 1

i v

1 2

2 4

true

i <= N

true

N = 6

Page 12: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

12

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 2

0 1

i v

1 2

2 4

true

i <= N

true

true

N = 6

Page 13: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

13

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 4

0 1

i v

1 2

2 4

true

i <= N

true

true

N = 6

Page 14: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

14

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 4

0 1

i v

1 2

2 4

3

true

i <= N

true

true

N = 6

Page 15: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

15

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 4

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

N = 6

Page 16: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

16

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 4

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

N = 6

Page 17: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

17

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 8

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

N = 6

Page 18: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

18

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 8

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4

N = 6

Page 19: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

19

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 8

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

N = 6

Page 20: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

20

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 8

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16 true

N = 6

Page 21: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

21

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 16

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16 true

N = 6

Page 22: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

22

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 16

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5

true

N = 6

Page 23: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

23

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 16

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

true

N = 6

Page 24: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

24

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 16

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

true

true

N = 6

Page 25: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

25

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 32

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

true

true

N = 6

Page 26: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

26

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 32

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6

true

true

N = 6

Page 27: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

27

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 32

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

true

true

N = 6

Page 28: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

28

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 32

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

true

true

true

N = 6

Page 29: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

29

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 326 64

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

true

true

true

N = 6

Page 30: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

30

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 326 64

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

7

true

true

true

N = 6

Page 31: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

31

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 326 64

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

7 128

true

true

true

N = 6

Page 32: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

32

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 326 64

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

7 128

true

true

true

false

N = 6

Page 33: 1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i

33

Powers of Two: Trace

Ex. Print powers of 2 that are 2N. Increment i from 0 to N. Double v each time.

int i = 0;int v = 1;while (i <= N) { System.out.println(i + " " + v); i = i + 1; v = 2 * v;}

0 11 22 43 84 165 326 64

0 1

i v

1 2

2 4

3 8

true

i <= N

true

true

true

4 16

5 32

6 64

7 128

true

true

true

false

N = 6