import java.util.Random; public class Demo1{ public static void main(String[] args) { int[] array = getRandom(3,9,-1); iterArray(array); System.out.println("end..."); } //产生10个随机数5-9之间 //返回值类型:int[] //参数列表:int min,int max,int count /** * [getRandom description] * @param min [description] * @param max [description] * @param count [description] * @return [description] */ public static int[] getRandom(int min,int max,int count){ //入参检查 if(count<=0||min>=max){ return null; } int[] array = new int[count]; Random r = new Random(); for(int i=0;i<count;i++){ array[i] = r.nextInt(max-min+1)+min; } return array; } /** * [iterArray description] * @param array [description] */ public static void iterArray(int[] array){ //入参检查 if(array==null){ System.out.println("传入数组为空"); return; } for (int num:array) { System.out.print(num+" "); } System.out.println(); } public static long sum(int[] a){ long sum = 0; for (int num:a) { sum += num; } return sum; } }