编写一个比较复杂的if语句

高考开始了

各校分数出线了:

理科:一本录取线:580;二本录取线:500;专录取线:300;

文科:一本录取线:600;二本录取线:520;专录取线:320;

要求:张三是理科生高考558分,可以去哪类学校;

输入文理科和分数得到学校;

代码示例:

Scanner sc = new Scanner(System.in);
System.out.println("输入姓名:");
String name =sc.next();
System.out.println("你是“文科”“理科”:");
String subject =sc.next();
System.out.println("输入你的分数:");
int score =sc.nextInt();
System.out.println( name+":"+subject+"  \t"+"成绩:"+score);
if(subject.equals("文科")){
    if(score > 750){
        System.out.println("你想上天");
    }else if(score <= 750&& score >= 600){
        System.out.println("恭喜达到一本录取线");
    }else{
        if(score <= 600&& score >= 520){
            System.out.println("恭喜达到二本录取线");
        }else{
            if(score <= 520&& score >= 320){
                System.out.println("恭喜达到专科录取线");
        }else{
                System.out.println("人生苦短,社会险恶,继续努力");
            }
        }
    }
}else if(subject.equals("理科")){
    if(score > 750){
        System.out.println("你想上天");
    }else if(score <= 750&& score >= 580){
        System.out.println("恭喜达到一本录取线");
    }else{
        if(score <= 580&& score >= 500){
            System.out.println("恭喜达到二本录取线");
        }else{
            if(score <= 500&& score >= 300){
                System.out.println("恭喜达到专科录取线");
            }else{
                System.out.println("人生苦短,社会险恶,继续努力");
            }
        }
    }
}else {
    System.out.println("请正确输入学科:文科&理科");
}

运行结果:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值