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));
}
}
}
标签:count,JAVA,Scanner,int,平均数,sum,number,nextInt,任意 来源: https://blog.csdn.net/luorain1013/article/details/119105904