Scanner sc=new Scanner(System.in);
int j=0,z=0;
int temp=0;
double count1=0,count2=0;
System.out.println("请输入10个数:");
for (int i=0;i<10;i++){
try {
System.out.print("输入第"+(i+1)+"个数:");
temp=sc.nextInt();
}catch (Exception e){
System.out.println("程序错误");
break;
}
if (temp<0){
System.out.println("请输入正整数!\n程序结束!");
break;
}else
if (temp%2==0){
count1=count1+temp;
j++;
}else{
count2=count2+temp;
z++;
}
}
if (j==0){
System.out.println("共有"+j+"个奇数,平均值为:0");
}else{
System.out.println("共有"+j+"个偶数,平均值位:"+(count1/j));
}
if (z==0){
System.out.println("共有"+z+"个奇数,平均值为:0");
}else{
System.out.println("共有"+z+"个奇数,平均值为:"+(count2/z));
}