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

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

5-6. Write a code that, for given integers m and n, computes the sum m2 + (m + 1)2 + ... + n2. Trace your code for m = 2 and n = 3.

















































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