CS 1401, Quiz 7 based on Test 2, TR version

Date: Tuesday, October 21, 2014
Name (please type legibly, ideally in block letters): ______________________________________________________________________

5-6. Write a code that, given an integer n, computes the sum

1   1   1         1
- + - + - + ... + -
1   2   3         n
Trace your code for n = 3. Caution: What will happen if you write 1 / 2 in Java?












































7. Trace, step-by-step, what will be the result of following Java code:
int n = 13;
String bin = "";
while(n > 0){
  if (n % 2 == 1)
    {bin = "1" + bin;}
  else
    {bin = "0" + bin;}
  n = n / 2;
}
{System.out.println(bin);}
Draw the boxes corresponding to all the variables, and show all the changes of their values.