Java Reference
In-Depth Information
100 assignment statements; instead, use loops. Write a program segment to com-
pute the mean, median, and total weight of the balls.
E3. A different method of storing the bowling balls of the previous exercise is to
use an array of seven elements, one for each weight, and to store the number of
balls with each weight. Redo the previous exercise using this method. Discuss
E4. Write (and test) statements to do the following.
(a) Set the elements of int array segment b[h..k] to 0 .
(b) Print the values of b[0..3] on the Java console on one line, separated
by blanks.
(c) Print the values of array b on the Java console, three on a line, with
blanks separating the three.
(d) Print the values of array b in reverse order on the Java console, three on
a line, with blanks separating the three.
(e) Add 1 to each element of int array b .
(f) Store in x the sum of the values of array segment b[h..k] .
(g) Store in x the sum of every other value of b[h..k] , beginning with the
first.
(h) Store in x the sum of every other value of b[h..k] , beginning with the
second.
(i) Find the largest value of int array segment b[h..k-1] .
(j) Find the largest value of int array segment b[h..k-1] , considering
only every other value beginning with the first.
(k) Store the largest and smallest values of array b[h..k-1] , where h<k ,
in variables small and large . Use a single loop.
E5. A polynomial is an expression of the form a 0 +a 1 x 1 +a 2 x 2 + ... + a n x n .
Write a function that computes the value of the polynomial given, as arguments,
the integer n, the value x , and an array a that contains the coefficients a 0 , ..., a n .
Make sure you specify the function properly.
E6. Write a function that tells how many odd numbers an int array contains.
E7. Write a function that tells how many elements of an int array have the value
x (the array and x are parameters of the method.)
E8. Write a function that computes the average of the values of a double array
segment b[h..k] .
E9. Write a procedure that does the following. Each element of array segment
b[0..n-1] contains a different integer in the range 0..n-1 . The array segment
contains a permutation of the values 0..n-1 . Print the elements of b[0..n-1] in
the following order: Print b[0] ; then, assuming that b[0]=j , print b[j] ; then,
assuming b[j]=k , print b[k] ; etc. In other words, print b[0] , b[b[0]] ,
b[b[b[0]]] , etc.

Search WWH ::

Custom Search