JAVA求任意个数字的平均数(输入-1截止)

package Hello;

import java.util.Scanner;

public class call_number {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
        Scanner in =new Scanner(System.in);
		int number = in.nextInt();
		int sum = 0;
		int count = 0 ;
		do {
			if(number !=-1)
			{
 				number = in.nextInt();
                sum=sum+number;
				count=count+1;
			}
		}while(number !=-1);
		if(count>0) {
			System.out.println("平均数为:"+(double)(sum/count));	
		}
		
	}

}

上一篇:租车订单最大收益


下一篇:JavaStudy:奇数求和