Q5:Java中控制台输入成绩用if..else判断成绩等级

前言

条件判断的语法:if()…else if()…else

一、具体实现

import java.util.Scanner;

public class Day02_1 {
    
    

	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		
		//创建scanner   scoreInput对象
		Scanner scoreInput = new Scanner(System.in);
		
		//输入提示
		System.out.println("请输入你的成绩");
		
		//调用scoreInput方法,定义score接收用户输入值
		int score = scoreInput.nextInt();
		
		String result = new String("结果");
		
		//判断分数等级
		if(score >= 90) {
    
    
			result = new String("你优秀了");
		}else if(score >= 80) {
    
    
			result = new String("你是良");
		}else if(score >= 60) {
    
    
			result = new String("你及格了");
		}else if(score < 60) {
    
    
			result = new String("你不及格,你完了");
		}else {
    
    
			//输入错误
			result = new String("这输入什么呀这是!");
		}
		System.out.println(result);
	}
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xavvgu/article/details/109092582
Q5