第1个回答 2013-12-05
最简单的实现方法
package com.Jack.main;
public class Random {
public static void main(String[] args) {
int item = 0;
int []a = new int[5];
System.out.print("生成的5个随机数分别是:");
for (int j = 0; j < 5;j++) {
item = ((int) (40*Math.random()))+20;
a[j]=item;
System.out.print(item+"、");
}
System.out.println();
System.out.println();
System.out.print("输出随机数中为偶数:");
for (int i = 0; i < a.length; i++) {
if(a[i]%2==0){
System.out.print(a[i]+"、");
}
}
}
}