use of minimum values with array's in simple problems
<p>I'm learning Java and as part of my work requires that I be able to do things like calculate the range of values in an array (max - min + 1). I'm not allowed to use methods like collections.min(array). So far my solution is like this:</p>

<pre><code>public static int range(int[] data){
int min = 99999999;
int max = 0; 
int test = 0;
int range = 0;
for (int i = 0; i &lt; data.length; i++){
     test = data[i];

     if (test &gt; max)
         max = test;
     if (test &lt; min) 
         min = test;
}
range = (max - min) + 1;
return range; 
</code></pre>

<p>}</p>

<p>While it works for them it isn't particularly elegant. Having a minimum value of  9999999 works but if I end up having a problem using numbers larger than that, it doesn't work. </p>

<p>I feel like there should be a better solution but I'm not seeing a way to find the minimum value without setting my int min to a very high value. Otherwise the array may have very large numbers and the minimum would never change since the value's in the array are always greater than it. </p>