输入任意多个数字,以-1结束输入;计算它们的平均值并输出。
import java.util.Scanner;
public class Avrage {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int number = 0,count = 0, temp;
temp = in.nextInt();
while(temp != -1)
{
number = number + temp;
count = count + 1;
temp = in.nextInt();
}
System.out.println("平均数为="+ 1.0*number/count);
}
}