Answer questions about the following code segment. Try and answer these questions
by tracing the code by hand.
int i, n, result;
i = 0;
n = StdIn.readInt();
result = 1;
while (i < n) {
result = result * 2;
i = i + 1;
}
StdOut.println(result);
- If the user entered 10 what would the output be?
- If the user entered 0 what would the output be?
- For any non-negative integer n what does the code segment compute?
- Does the program "work" if the user enters a negative number? That is, is it
consistent with your previous answer in part c?