public class Test {
public static void main(String[] args) {
int[] n = {325,2362,123,6,123,-8,-235,23};
getMaxMin(n);
}
static void getMaxMin(int[] n){
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i=0;i<n.length;i++){
if(min>n[i]){
min = n[i];
}
if(max<n[i]){
max = n[i];
}
}
System.out.println("最大值:"+max);
System.out.println("最小值"+min);
System.out.println("相差:"+(max-min));
}
}
温馨提示:答案为网友推荐,仅供参考