Java练习题之分支结构

题一:编写一个程序,输出如下结果:

  • 85-100分: 优,非常棒!
  • 85分以下: 良,下次加油!

输出结果如下:

代码如下:

  • import java.util.Scanner;
    
    public class Score {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		System.out.println("请输入学员成绩:");
    		Scanner scan = new Scanner(System.in);
    		int score = scan.nextInt();
    		if (score > 85 && score < 100) {
    			System.out.println("优,非常棒!");
    		} else {
    			System.out.println("良,下次加油!");
    		}
    
    	}
    
    }
    

题二:

编写一个星级成绩评定系统,规则如下:

  • 90分及以上:五星成绩。

  • 80-90分(包括80分,不包含90分): 四星成绩。

  • 70-80分(包括70分,不包含80分): 三星成绩。

  • 60-70分(包括60分,不包含70分): 俩星成绩。

  • 60分以下(不包含60分):无星成绩。

程序运行结果如下:

import java.util.Scanner;

public class Score {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("星级成绩评定系统");
		System.out.println("请输入成绩:");
		Scanner scan = new Scanner(System.in);
		int score = scan.nextInt();
		if (score >= 90) {
			System.out.println("⭐⭐⭐⭐⭐五星成绩");
		} else if (score >= 80 && score < 90) {
			System.out.println("⭐⭐⭐⭐四星成绩");
		} else if (score >= 70 && score < 800) {
			System.out.println("⭐⭐⭐三星成绩");
		} else if (score >= 60 && score < 70) {
			System.out.println("⭐⭐俩76星成绩");
		} else if (score < 60) {
			System.out.println("无星成绩");
		}

	}

}

题三:用Switch完成一个能根据用户输入的月份,给出对应的季节的小程序。

运行结果如下:

 代码:

import java.util.Scanner;

public class Score {

	public static void main(String[] args) {
		System.out.println("请输入月份:");
		Scanner scanner = new Scanner(System.in);
		int month = scanner.nextInt();
		switch (month) {
		case 1:
			System.out.println("1月份是冬天");
			break;
		case 2:
			System.out.println("2月份是冬天");
			break;
		case 3:
			System.out.println("3月份是春天");
			break;
		case 4:
			System.out.println("4月份是春天");
			break;
		case 5:
			System.out.println("5月份是春天");
			break;
		case 6:
			System.out.println("6月份是夏天");
			break;
		case 7:
			System.out.println("7月份是夏天");
			break;
		case 8:
			System.out.println("8月份是春天");
			break;
		case 9:
			System.out.println("9月份是秋天");
			break;
		case 10:
			System.out.println("10月份是秋天");
			break;
		case 11:
			System.out.println("11月份是秋天");
			break;
		case 12:
			System.out.println("12月份是冬天");
			break;
		}

	}

}

猜你喜欢

转载自blog.csdn.net/qq_60536278/article/details/127583666