import java.util.Scanner;
public class Huang {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int flag = 0;
do {
System.out.print("你想取得的总评分是?");
double target = sc.nextInt();
System.out.print("你当时的评分是?");
double peacetimeScore = sc.nextInt();
if (peacetimeScore >= 0 && peacetimeScore <= 40 && target >= 0 && target <= 100) {//判断是否符合条件
double examScore = (target - peacetimeScore) / 0.6;//计算期末需考的分
System.out.println("期末需要考:" + examScore);
} else {
System.out.println("重新输入:");//不符合条件则重新输入
}
System.out.print("是否继续计算?(Y?N)");//可以进行下一次运算
Scanner scan = new Scanner(System.in);
char choice;
choice = scan.next().charAt(0);
if (choice == 'y' || choice == 'Y') {//选择进入下一次运算
flag = 1;
} else {
flag = 0;
}
}while (flag == 1);//判断是否循环的条件
}
}
期末所需分数的代码及其简单解析
最新推荐文章于 2025-05-08 10:00:08 发布