All pastes #242224 Raw Edit

Tiko

public java v1 · immutable
·published 2006-11-07 00:52 UTC
rendered paste body
public static void main(String args[]) {        double[] test1 = new double[4];        test1[0] = 500;        test1[1] = 100;        test1[2] = 1000;        test1[3] = 0.1;        System.out.println("1: "+findMin(test1, 0, 1)); //100.0        System.out.println("2: "+findMin(test1, 2, 3)); //0.1        System.out.println("3: "+findMin(test1, 0, 0)); //500.0    }    public static double findMin(double[] numbers, int startIndex, int endIndex) {        //I don't know how your teacher wants to handle the indices, like whether they are zero-based or not        //for now I assume they are        //do error checking here like if startindex is < 0 or endindex is > than numbers.length        double lowest = numbers[0]; //give this a value to start comparing        for (int i = startIndex; i <= endIndex; i++) {            //is the current number lower than the previous lowest?            if (numbers[i] < lowest) {                lowest = numbers[i]; //if so make it the lowest            }        }        return lowest;    }