返回列表 發帖
  1. import java.util.*;
  2. public class JPA02{
  3. static Scanner keyboard = new Scanner(System.in);
  4. public static void main(String[] args) {
  5.   test();
  6.   test();
  7.   test();
  8.   test();
  9.   test();
  10. }
  11. public static void test() {
  12.   System.out.println("Input a character:");
  13.   String c = keyboard.nextLine();
  14.   switch(c.charAt(0)) {
  15.   case 'a':
  16.   case 'b':
  17.    System.out.println("You entered a or b");
  18.    break;
  19.   case 'x':
  20.    System.out.println("You entered x");
  21.    break;
  22.   case 'y':
  23.    System.out.println("You entered y");
  24.    break;
  25.   default:
  26.    System.out.println("You entered something else.");
  27.    break;                     
  28.   }
  29. }
  30. }
複製代碼

TOP

返回列表