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);

Recommended Answers

All 2 Replies

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.

commented: Thanks! +0

What is value in the "n [0]"?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.