01: //File: NumberList.java
02: import iostuff.*;
03: public class NumberList
04: {
05: //The following method finds the smallest item in a list of integers
06: public static int smallest (int [] list)
07: {
08: int smallestSoFar;
09:
10: //The following focuses on smallestSoFar,
11: //a variable that is compared with each item
12: //in the list in succession. As smaller items
13: //are encountered, they are assigned to the variable
14: //smallestSoFar.
15: smallestSoFar = list[0];
16: for (int k=1; k<list.length; k++)
17: {
18: if (list[k] < smallestSoFar)
19: {
20: smallestSoFar = list[k];
21: }
22: }
23: return smallestSoFar;
24: }
25:
26: //The following method outputs to the screen a list of integers
27: public static void display (int [] list)
28: {
29: for (int k=0; k<list.length; k++)
30: {
31: System.out.println (list[k]);
32: }
33: }
34:
35: public static int average (int [] a)
36: {
37: int sum=0;
38: for (int k=0; k<a.length; k++)
39: {
40: sum = sum + a [k];
41: }
42: return sum/a.length;
43: }
44:
45: public static double average (double [] a)
46: {
47: double sum=0;
48: for (int k=0; k<a.length; k++)
49: {
50: sum = sum + a [k];
51: }
52: return sum/a.length;
53: }
54:
55: }