[Java] Switch條件式

import java.util.Scanner;

public class Level {
    public static void main(String[] args){
        //int scor =88;
        //int quotient = scor/10;
        //char level;
        Scanner scanner = new Scanner(System.in);
        System.out.println("Please type score: ");
        int score = scanner.nextInt();
        int quotient = score /10;
        char level;
        switch(quotient){
            case 10:
            case 9:
                level = 'A';
                break;
            case 8:
                level = 'B';
                break;
            case 7:
                level = 'C';
                break;
            case 6:
                level = 'D';
                break;
            default:
                level = 'E';
                break;
        }
        System.out.printf("成績為%c%n",level);
    }
}

留言

這個網誌中的熱門文章

[Excel]國曆轉農曆VBA

「生活」眉毛觀人

「CSS」「div區塊介紹」 三欄式網頁排版設計