1 package zuoye; 2 3 import java.util.Random; 4 5 public class Test1 { 6 public static void main(String[] args) { 7 Random rand = new Random(); 8 int arr[] = new int[10]; 9 for (int i = 0; i < arr.length; i++) { 10 arr[i] = rand.nextInt(100); 11 System.out.print(arr[i] + " "); 12 } 13 System.out.println(); 14 RandomNum rn = new RandomNum(arr); 15 } 16 } 17 18 class RandomNum { 19 int arr[]; 20 21 public RandomNum(int arr[]) { 22 this.arr = arr; 23 } 24 25 public double getMaxNum(int arr[]) { 26 int max = arr[0]; 27 for (int i = 0; i < arr.length; i++) { 28 if (arr[i] > max) 29 max = arr[i]; 30 } 31 System.out.println("The max num of the array is " + max); 32 return max; 33 } 34 35 }