Answers to Self-Test Questions

  1. 1. 0 2 4 6 8 10 12 14 16 18

  2. 2.

    a
    e
    i
    o
    u
  3. 3.

    Tide 1 is −7.3|
    Tide 2 is 14.2
  4. 4. The last index of a is 9. The value of a.length is 10.

  5. 5. The for loop references elements b[1] through b[10], but there is no element indexed by 10. The array elements are b[0] through b[9]. If included in a complete class or program, the code would compile without any error messages, but when it is run, you would get an error message saying that an array index is out of bounds.

  6. 6. 1.

    import java.util.Scanner;
    public class Question6
    {
        public static void main(String[] args)
        {
            double[] array = new double[20];
            Scanner keyboard = new Scanner(System.in);
            System.out.println("Enter 20 numbers:");
            for (int index = 0; index <array.length; ...

Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.