其他分享
首页 > 其他分享> > 判断及格

判断及格

作者:互联网

编写一个程序,此程序在运行时要求用户输入一个 整数,代表某门课的考试成绩,程序接着给出“不及格”、“及格”、“中”、“良”、“优”的结论。

package testing;
import java.util.Scanner;

public class panduan {
    public static void main(String[] args) {
        String str="";
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入分数:");
        str = sc.next();
        double score;
        try {
            score = Integer.parseInt(str);
            if(score>=0&&score<60)
                System.out.println("不及格");
            else if(score>=60&&score<70)
                System.out.println("及格");
            else if(score>=70&&score<80)
                System.out.println("中");
            else if(score>=80&&score<90)
                System.out.println("良");
            else if(score>=90&&score<100)
                System.out.println("优秀");
            else
                System.out.println("分数输入不正确");
        }catch(Exception e) {
            System.out.println("分数输入不正确");
        }
    }
}

 

标签:及格,判断,&&,System,String,score,str,Scanner
来源: https://www.cnblogs.com/manmmm/p/15599796.html