/*
* 读入指定个数的整数,判断读入的整数有多少,读入的负数有多少,然后计算总和和平均值,当输入为0时,表明程序结束
*/
import java.util.Scanner;
public class Count01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int count1 = 0, count2 = 0;
double total = 0.0, averagr;
System.out.println("Enter an integer , the input ends if it is 0: ");
while (sc.hasNext()) {
int a = sc.nextInt();
if (a > 0) {
count1++;
total = total + a;
} else if (a < 0) {
count2++;
total = total + a;
} else {
if (count1 == 0 && count2 == 0) {
System.out.println("No numbers are entered except 0");
System.exit(0);
}
break;
}
}
sc.close();
System.out.println("The number of postives is " + count1);
System.out.println("The number of negatives is " + count2);
System.out.println("The total is " + total);
System.out.println("The average is " + (total / (count1 + count2)));
}
}