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

import java.util.Scanner;
public class Chen {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true) {
            System.out.print("你目前的平时分是:");
            int peacetimeScore = sc.nextInt();
            System.out.print("你的目标分数是:");
            int soal = sc.nextInt();
            if (peacetimeScore >= 0 && peacetimeScore <= 40) {
                if (soal >= 0 && soal <= 100) {
                    int target = soal;
                    int realExamScore = target - peacetimeScore;
                    double examScore = realExamScore / 0.6;
                    if (examScore > 100) {
                        System.out.println("达不到这个分数");
                    } else {
                        System.out.printf("你期末需要考%.1f分才能达到目标分数\n", examScore);
                    }
                } else {
                    System.out.println("错误;你的目标分应在0到100之间");
                }
            } else {
                System.out.println("你的平时分应在0到40分之间");
            }
        }

    }
}
import java.util.Scanner;//导入scanner类,用于从控制台读取用户输入
public class Chen {//定义一个名为FishTank的类,类是Java程序的基本组成部分
    public static void main(String[] args) {//main方法是程序的入口,程序从这里开始执行

        Scanner sc=new Scanner(System.in);//创建一个Scanner对象,sc用于读取用户输入

        while(true) {

            System.out.print("你目前的平时分是:");

            int peacetimeScore = sc.nextInt();

            System.out.print("你的目标分数是:");

            int soal = sc.nextInt();

            if (peacetimeScore >= 0 && peacetimeScore <= 40) {

                if (soal >= 0 && soal <= 100) {

                    int target = soal;

                    int realExamScore = target - peacetimeScore;

                    double examScore = realExamScore / 0.6;

                    if (examScore > 100) {

                        System.out.println("达不到这个分数");

                    } else {

                        System.out.printf("你期末需要考%.1f分才能达到目标分数\n", examScore);

                    }

                } else {

                    System.out.println("错误;你的目标分应在0到100之间");

                }

            } else {

                System.out.println("你的平时分应在0到40分之间");

            }

        }



    }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值