import java.util.Scanner;
public class BreakScore{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("输入学生姓名:");
String name = sc.nextLine();
int score = 0;
int sum = 0;
for(int i = 1;i <=5; i++){
System.out.print("请输入" + name + "第" + i + "门课的成绩:");
score = sc.nextInt();
if(score < 0){
System.out.println("抱歉,分数录入错误,请重新进行录入!");
i--;
continue;
}
sum += score;
}
System.out.println(name + "五门课的平均成绩为:" + sum/5.0);
}
}
Java基础语法之continue语句跳出本次循环——录入学生成绩并计算平均值
最新推荐文章于 2024-07-05 17:14:28 发布