代码如下:
public class demo {
public static void main(String[] args) {
int[]nums= new int[10];
for (int i=0;i<nums.length;i++){
nums[i]=((int)(Math.random()*10000))%1001;
}
System.out.println("数组元素:");
for (int i = 0; i < nums.length; i++) {
System.out.print(nums[i]+",");
}
int count = 0;
int count2 = 0;
for (int i = 1; i < nums.length; i++) {
if(nums[i]%2==0){
count++;
}else{
count2++;
}
}
System.out.println();
System.out.println("偶数的个数为:"+count+"个,"+"奇数的个数为:"+count2+"个");
}
}
运行结果:
数组元素:
856,487,602,868,600,82,971,145,882,766,
偶数的个数为:6个,奇数的个数为:3个