### Example: The PowerOfTwo Program

In order to demonstrate the Gild Debugger, we must first have a program that needs debugging. In order to have a program, we must have a problem that we need to solve. Our problem is this:

1. We want to compute all of the powers of two from 1 up to and including 32.
2. Each power of two should be printed, one power per line, using a descriptive message.
3. After all of the powers of two have been computed, we want to print the final power of two (32), using "caret" notation (2^i-where '^' is called a "caret", and i is the exponent of the power of two). This number will be printed on a separate line, immediately after all of the other messages.

As a solution to this problem, we have the following Java source code:

The program gives the following output:

    The current power of 2 is 1
    The current power of 2 is 3
    The current power of 2 is 5

    .	.	.

    The current power of 2 is 29
    The current power of 2 is 31
    2^16 = 33

There are a few problems with the output. First, we can see that none of the lines, except the first, actually give a power of two; second, the message lines do not print numbers up to and including 32; third, 2^16 does not equal 33. Let's use the debugger to try and understand what is going on.

Previous | Next