package com.ww.yzpB; public class maxMin { public void MaxMin(int[] number) { int max =number[0]; for (int i = 0; i < number.length; i++) { if(number[i]>max){ max=number[i]; } } int min=number[0]; for (int i = 0; i < number.length; i++) { if(number[i]<min){ min=number[i]; } } System.out.println("\n最大值:"+max+"最小值:"+min); } } package com.ww.yzpB; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub maxMin maxmin = new maxMin(); int rondom [] = new int [10]; System.out.print("10个随机数为:"); for (int i = 0; i < rondom.length; i++) { rondom[i]=(int)(Math.random()*1000); System.out.print(rondom[i]+" "); } maxmin.MaxMin(rondom); } }