本帖最后由 MMM521 于 2017-4-1 22:38 编辑
import java.util.Scanner;
public class Score {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sum = 0;
int count=0;
while (true) {
System.out.println("请输入学生成绩:");
int score = sc.nextInt();
if (score == -1) {
break;
} else {
sum += score;
count++;
}
}
System.out.println("学生成绩的平均值为"+sum/count);
}
}
|