zl程序教程

您现在的位置是:首页 >  其他

当前栏目

利用if语句求解成绩等级问题

2023-02-19 12:20:50 时间

1 问题

成绩进行划分等级,人工划分容易出错,且数量庞大。

2 方法

public class Text06 {

   public static void main(String[] args) {

       int score=100;

       System.out.println("score");

       // 1.成绩大于等于85

       if (score>=85){

           System.out.println("A");

       }

       //2.成绩在70到85之间(包含70)

       else if (score>=70&&score<85){

           System.out.println("B");

       }

       //3.成绩在60到70之间(包含60)

       else if (score>=60&&score<70){

           System.out.println("C");

       }

       //4.成绩在60分以下

        else {

           System.out.println("D");

       }

   }

}

3 结语

针对成绩等级问题,提出使用Java相关代码的方法,通过利用if语句,证明该方法是有效的,该方法在判断过程中快捷有效,并且不容易出错,在生活中也常用。