2019-09-28 11:15:22 +08:00
|
|
|
package Maths;
|
|
|
|
|
|
|
|
public class FindMin {
|
|
|
|
|
|
|
|
//Driver
|
|
|
|
public static void main(String[] args) {
|
|
|
|
int[] array = {2, 4, 9, 7, 19, 94, 5};
|
2020-08-10 16:52:06 +08:00
|
|
|
assert findMin(array) == 2;
|
2019-09-28 11:15:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-24 04:22:14 +08:00
|
|
|
* Find the minimum number of an array of numbers.
|
2019-09-28 11:15:22 +08:00
|
|
|
*
|
|
|
|
* @param array the array contains element
|
|
|
|
* @return min value
|
|
|
|
*/
|
2019-11-19 16:40:29 +08:00
|
|
|
public static int findMin(int[] array) {
|
2019-09-28 11:15:22 +08:00
|
|
|
int min = array[0];
|
|
|
|
for (int i = 1; i < array.length; ++i) {
|
|
|
|
if (array[i] < min) {
|
|
|
|
min = array[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
}
|