7.1 Solutions

    1. marks
    2. marks[0]
    3. 0
    4. 20
    5. 0, 1, 2, ... 19
    1. 20 x 32 = 640 (32 bits in 1 int)
    2. 100 x 64 = 6400 (64 bits in 1 double)
    3. 50 x 32 =1600 (32 bits in 1 float)
    4. 1000 x 1 = 1000 (1 bit in a boolean)
    1. int[] votes = new int[5];
    2. boolean[] answers = new boolean[20];
    3. float[] familySize = new float[11];
    1. float[] terms = new float[6];
      for (int i = 1; i < 7; i++)
        terms[i-1] = i/(float)(i+1);
    2. or
      float[] terms = new float[7];
      for (int i = 1; i < 7; i++)
        terms[i] = 1.0*i/(i+1);
      or
      float[] terms = {0, 1.0/2, 2.0/3, 3.0/4, 4.0/5, 5.0/6, 6.0/7};
      
      
    3. In first example it would be 6 in last two it would be 7.
      The first example wastes no space, the other two waste the first element in the array (terms[0] is not used). However the other two are easier to understand and terms[1] = t1. In first example terms[0] = t1
    1. 4.0
    2. 10.8
    3. 0, 1, 2, ... 8
    4. mass[3]
    5. float
    6. 9