返回列表 發帖

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. }
複製代碼

回復 1# tonyh
  1.                 import java.io.Console;
  2. public class ch09
  3. {
  4.   public static void main(String args[])
  5.   {
  6.     Console keyin=System.console();
  7.     int int1;
  8.     Float ft2;
  9.     System.out.print("請你的成績:");
  10.     int1=Integer.parseInt(keyin.readLine());
  11.     int1=int1/10;
  12.     switch(int1)
  13.     {
  14.     case 10:
  15.     System.out.print("恭喜您當老師了!");
  16.     break;
  17.     case 9:  case 8:  case 7:  case 6:
  18.     System.out.print("恭喜您及格了!");
  19.     break;
  20.     case 5:   case 4:  case 3:  case 2:  case 1:
  21.     System.out.print("恭喜您重修了!");
  22.     break;
  23.     case 0:
  24.     System.out.print("恭喜您可以回家了!");
  25.     break;
  26.     default:
  27.     System.out.print("恭喜您亂打了!");
  28.     }
  29.   }
  30. }
複製代碼

TOP

  1. import java.io.Console;
  2. public class ch09
  3. {
  4.    public static void main (String showdemo[])
  5.    {
  6.     Console console=System.console();
  7.     int score;
  8.     int level;
  9.     System.out.print("Please input your score =");
  10.     score=Integer.parseInt(console.readLine());
  11.     level=score/10;
  12.     switch(level)
  13.     {
  14.     case 10 :
  15.           System.out.println("有作弊嗎? 太神了");
  16.           break;
  17.     case 9: case 8: case 7:case 6:
  18.           System.out.println("恭喜及格了!!");
  19.           break;
  20.     case 5:case 4:case 3:case 2:case 1:
  21.           System.out.println("成績不及格!!");
  22.           break;
  23.     case 0:
  24.           if (score >0)
  25.           {
  26.               System.out.println("成績不及格!!");
  27.           }
  28.           else
  29.           {
  30.               System.out.println("鴨蛋喔!!");
  31.           }
  32.           break;
  33.     default :
  34.           System.out.println("輸入錯誤,你是來亂的嗎?");

  35.     }
  36.    }
  37. }
複製代碼

TOP

返回列表