Array Worksheet One Answers

1.   x = 20
     y = 100


2.   x = 20
     y = 100


3.   x = 22
     y = 100


4.   x = 23
     y = 25


5.   x = 21
     y = 11


Given the following array:

      int[] a = new int[10];

Write a loop to do each of the following:


6.   for (i = 0 ; i < 10 ; i++)
        a[i] = a[i] + 1;


7.   count = 0;
     for (i = 0 ; i < 10 ; i++)
        if (a[i] < 0)
           count++;


8.   int[] b = new int[10];
     for (i = 0 ; i < 10 ; i++)
        b[i] = a[i];


9.   for (i = 9 ; i <= 0 ; i)
        System.out.println(a[i]);


10.  count = 0;
     for (i = 0 ; i < 10 ; i++)
        if (a[i] >= 10 && a[i] <= 20)
           count++;


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013