我需要找到数组中的最小值,但我想知道如何处理多个结果。假设我的数组包含[1,4,7,5,3,1]
- 我的结果应该是1,1
. 有任何想法吗?
double minimum = array1[0]; //sets the first to be the smallest
for (int i = 0; i < array1.length; i++) //goes through your array
{
if (array1[i] < array1[0]) //checks and replaces if necessary
{
minimum = array[i];
}
}
System.out.println( minimum ); //returns the value of the smallest