期末所需分数的代码及其简单解析

 
import java.util.Objects;
import java.util.Scanner;

public class FishTank {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean determineNumber = true;

        while (determineNumber) {
            System.out.print("你想取得的总评分数是:");
            int totalScore = sc.nextInt();
            if (totalScore < 0 || totalScore > 100) {
                System.out.println("非合法输入,总评分数为 0-100,请重新输入!");
                continue;  //不符合则返回while运行
            }

            System.out.print("你当前的平时分是:");
            int peacetimeScore = sc.nextInt();
            if (peacetimeScore < 0 || peacetimeScore > 40) {
                System.out.println("非合法输入,平时分数为 0-40,请重新输入!");
                continue;
            }

            double examScore = (totalScore - peacetimeScore) / 0.6;
            System.out.printf("你期末需要考%.1f 分才能达到想要取得的总评分\n", examScore);
            System.out.print("是否继续计算(y/n):");
            String choice = sc.next();  //选择是否继续计算
            if (Objects.equals(choice, "n")) {
                determineNumber = false;  //若choice=n则determineNumber=false,否则不变
            }
        }
    }
}

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值