954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Finding the minium valueof an array

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);
flyingcurry
Light Poster
44 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

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.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

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

moutanna
Posting Whiz
387 posts since Oct 2009
Reputation Points: 16
Solved Threads: 58
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: