How do I find max and min value of group of numbers.
int num[] = {1,2,3,4,5,6,7,8,9,2,2,2,2,2,};
getMaxValue(num);
getMinValue(num);
// getting the maximum value
public static int getMaxValue(int[] array){
int maxValue = array[0];
for(int i=1;i < array.length;i++){
if(array[i] > maxValue){
maxValue = array[i];
}
}
return maxValue;
}
// getting the miniumum value
public static int getMinValue(int[] array){
int minValue = array[0];
for(int i=1;i<array.length;i++){
if(array[i] < minValue){
minValue = array[i];
}
}
return minValue;
}