返回列表 發帖
  1. package test;

  2. import java.util.Scanner;

  3. public class JPA02 {
  4. static Scanner keyboard = new Scanner(System.in);
  5.         public static void main(String[] args) {
  6.                
  7.                 // TODO 自動產生的方法 Stub
  8.                 test();        
  9.         test();
  10.         test();
  11.         test();
  12.         }
  13.          static void test() {
  14.                  System.out.println("Input a character : ");
  15.                  String num=keyboard.nextLine();
  16.                  switch(num)
  17.                  {
  18.                  case"a":
  19.                  case"b":
  20.                  System.out.println("You entered a or b");
  21.                  break;
  22.                  case"x":
  23.                  System.out.println("You entered x");
  24.                  break;
  25.                  case"y":
  26.                  System.out.println("You entered y");
  27.                  break;
  28.                  default:
  29.              System.out.println("You entered something else.")                 
  30.                  }
  31.             }
  32.          }
複製代碼

TOP

返回列表