Chapter 9

EX 9-1
1.)An array can group similar data with on array that contains many elements.
2.)They use the name and the index to access it.
3.)

EX 9-2
1-a.)34
b.)4
c.)156
2.)The JVM checks the values of subscripts before using them and throws an ArrayIndexOutBoundsException if they are out of bound.

EX 9-3
1.)int i = 0 for (i==0, i=0; i –) System.out.print(a[i])
2.)int i = a.length – 1 for (i == a.length – 1; i>=0; i –) System.out.print(a[i])
3.)int index; for (int i =0; i < a. length; i ++){if (a[i] <0 ){index = i; break; } else {index = a.length;} System.out.print (index) ;
4-a.)It will change all the negative values of a to positive value by taking the absolute values of them.
b.)The loop will just get the sum of all elements of the a array.
5.)It tells the operator precisely how many elements inside the array.

EX 9-4
1-a.)double[] abc = new double[15]
b.)string[] abcd = new string[20]
2.)It is another way to initialize the array, it assign the exact values to the array’s element.
3-a.)int [] aaa = {100, 90, 75, 60, 88}
b.)double[] bbb = {0.12, 0.05, 0.15}
c.)string[] ccc = {nina, lu}
4.)

EX 9-5
1.)The programmer will try to solve the problem by tracking the array’s logical size with a separate integer variable.
2.)When the array is not full, it must replace the array;s physical length with its logical size in the loop.

EX 9-6
1.)A parallel array is situations in which it is convenient to declare.
2.)One array should contain the exponent and the other array should contain 2 raised to that power.
3.)String [] name = new String[50]int [] age = new int [50]int [] security = new int [50]String searchPerson;int correspondingAge = -1, correspondingSecurity = -1searchName = …for (int i = 0, i<name.length; i ++) if (searchName.equal (name[i]))correspondingAge = age [i]correpondingSecurity = security [i]break;}
4.)
5.)int[] exponent = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] powers = new int[10];
for (int i = 0; int < 10; i++){
power [i] = math.pow(2, exponent[i])
} ;

EX 9-7
1.)An array in which each data item is accessed by specifying a pair of indices.
2.)If an application require the variable tale reference an array of four elements. Each of these elements in turn reference and array of five integers. And the application will need to use two dimensional arrays.
3.)
4.)

Published in: on February 14, 2008 at 5:10 pm  Leave a Comment  
Follow

Get every new post delivered to your Inbox.