package com.ithema;
import java.util.Scanner;
/*1.键盘录入学生成绩(整数类型),如果录入的成绩为-1表示录入结束
2.打印输出录入的学生成绩的平均值*/
public class Test8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum=0;int count=0;
while(true){
System.out.println("请输入学生得学生成绩");
int stuScore=sc.nextInt();
sum+=stuScore;
count++;
int avg=sum/count;
if(stuScore==-1){
System.out.println(count);
System.out.println(sum);
System.out.println(avg);
break;
}
}
}
} |