Exercise 3a        Name __________________        Score __/13

  1. (4) Give the object diagram for the following fixed size array declarations similar to a right for:
                        int [] hours = int[24];

     

    1. int [ ] A;
      A = new int [ 4 ];

    2. boolean [ ] B;
      B = new boolean [ 3 ];
       

       


       

  1. (4) From Question 1 add the following assignments to the object diagram:
    1. A
      • variable 0 the value -2
      • variable 1 the value -3
      • variable 2 the value -7
      • variable 3 the value -5
    2. B
      1. variable 0 the value true
      2. variable 1 the value false
      3. variable 2 the value true
         
  2. (3) From Question 2, what is:
     
    1. for (int i = 0; i < 4; i++)
          System.out.println(A [ i ] );    -2 -3 -7 -5
       
    2. for (int i = 3; i > 0; i--)
          System.out.println(A [ i ] );    -5 -7 -3
       
    3. for (int i = 0; i < 4; i++)
          System.out.println(B [ i ] );    true false true    Index out of range
       
    4. int sum = 0;
      for (int i = 0; i < 4; i++)
          sum = A [ i ] + sum;
      System.out.println( sum );        -17
       
    5. boolean sum = true;
      for (int i = 0; i < 3; i++)
          sum = B [ i ] && sum;
      System.out.println( sum );        false