if多选择结构
package com.wuming.struct;
import java.util.Scanner;
public class IfDemo03 {
? ? public static void main(String[] args) {
? ? ? ? //if多選擇
? ? ? ? /*
? ? ? ? * if語(yǔ)句最多一個(gè)else,且在else if之后
? ? ? ? * if可以有多個(gè)else if且在else之前
? ? ? ? * 若有一個(gè)else if為true,其他else if 和else跳過執(zhí)行
? ? ? ? * */
? ? ? ? Scanner scanner = new Scanner(System.in);
? ? ? ? System.out.println("請(qǐng)輸入成績(jī):");
? ? ? ? int score = scanner.nextInt();
? ? ? ? if (score == 100) {
? ? ? ? ? ? System.out.println("恭喜滿分");
? ? ? ? } else if (score < 100 && score >= 90) {
? ? ? ? ? ? System.out.println("A");
? ? ? ? } else if (score < 90 && score >= 80) {
? ? ? ? ? ? System.out.println("B");
? ? ? ? } else if (score < 80 && score >= 70) {
? ? ? ? ? ? System.out.println("C");
? ? ? ? } else if (score < 70 && score >= 60) {
? ? ? ? ? ? System.out.println("D");
? ? ? ? } else if (score < 60 && score >= 0) {
? ? ? ? ? ? System.out.println("不及格");
? ? ? ? } else{
? ? ? ? ? ? System.out.println("不合法");
? ? ? ? }
? ? ? ? scanner.close();
? ? }
}
請(qǐng)輸入成績(jī):
90
A
總結(jié)
- 上一篇: Python set集合 - Pytho
- 下一篇: BugkuCTF-WEB题好像需要密码