516
for(j = m – 1; j >= 0 ; j--)
outFile.println(a[j] + " "+ b[j] + " "+ (a[j] – b[j]));
outFile.println();
outFile.println(sumA + " "+ sumB + " "+ sumDiff);
Data
5
11
15
19
14
4
2
17
6
1
3
8.A person wrote the following code fragment, intending to print 10 20 30 40:
int[] arr = { 10 , 20 , 30 , 40 };
intindex;
for(index = 1 ; index <= 4 ; index++)
outFile.println(" "+ arr[index]);
Instead, the application halted with an exception. Explain the reason for this
output.
9.Given the declarations
int[] sample = new int[ 8 ];
inti;
intk;
show the contents of the array sampleafter the following code segment
executes. Use a question mark to indicate any undefined values in the array.
for(k = 0 ; k < 8 ; k++)
sample[k] = 10 – k;
10.Using the declarations and array contents of Exercise 9, show the contents of
the array sampleafter the following code segment executes.
for(i = 0 ; i < 8 ; i++)
if(i <= 3 )
sample[i] = 1 ;
else
sample[i] = – 1 ;