public class random
{
public static void main(String args[])
{int i;
int a[]=new int[10];
for (i=0;i<10;i++)
a[i]=(int)(Math.random()*100);
for (i=0;i<10;i++)
if (a[i]%2==0)
System.out.println(a[i]+"是偶数");
else
System.out.println(a[i]+"是奇数");
}
}
这是最简单的
int i=new Random().nextInt(100);
if(i%2==0)
System.out.println(i+"是偶数");
else
System.out.println(i+"是奇数");
double t=Math.random()*100;
int num=(int)Math.floor(t);
if(num%2==0)
System.out.println(num+"是偶数");
else
System.out.println(num+"是奇数");
用个Random就行了.