返回列表 發帖

switch 判斷式

  1. import java.lang.*;
  2. import java.io.Console;
  3. public class ch09
  4. {
  5.    public static void main(String args[])
  6.    {
  7.         Console console=System.console();
  8.         int score;
  9.         int level;
  10.         System.out.print("請輸入你的成績: ");
  11.         score=Integer.parseInt(console.readLine());
  12.         level=score/10;
  13.         switch(level)
  14.         {
  15.             case 10:
  16.                System.out.println("哇滿分!太神了!");
  17.                break;     //跳出
  18.             case 6: case 7: case 8: case 9:
  19.                System.out.println("恭喜你及格了!");
  20.                break;
  21.             case 0: case 1: case 2: case 3: case 4: case 5:
  22.                System.out.println("不及格!下次再努力!");
  23.                break;
  24.             default:
  25.                System.out.println("輸入錯誤!");
  26.         }
  27.    }
  28. }
複製代碼

返回列表