我正在编写一个程序来计算用户输入的平均值。
import java.util.Scanner;
public class mean
{
static Scanner input = new Scanner (System.in);
public static void main (String[] args)
{
double i;
double sum = 0;
int count = 0;
do
{
System.out.println("input");
i = input.nextDouble();
sum = sum + i;
count++;
}while (i != 0);
System.out.println("sum is " + sum + " count is " + (count - 1));
System.out.println("average is " + sum / (count - 1));
}
}
这里如果我输入0,它会计算。但如果列表中有 0。有人可以指导我一段时间吗?