0

Beginner in Java.
I am trying to find the highest value and lowest value of an array.
The highest value works perfectly fine, while the lowest value keeps on giving me 0, even though 0 is not part of the array. Below is the code. Thanks.

mxm = n [0];
        for (x = 1 ; x <= 15 ; x++)
        {
            if (n [x] > mxm)
            {
                mxm = n [x];
            }
        }
        c.println ("The largest integer out of the 15 generated is " + mxm);

        min = n [0];
        for (x = 1 ; x <= 15 ; x++)
        {
            if (n [x] < min)
            {
                min = n [x];
            }
        }
        c.println ("The smallest integer out of the 15 generated is " + min);

Edited by flyingcurry: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by moutanna
1

You should set your initial lowest value to array[0], otherwise the lowest value variable will probably be initialized to 0, therefore, it will tell you the lowest value is 0 at the end.

Votes + Comments
Thanks!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.