- package test;
- import java.util.Scanner;
- public class JPA02 {
- static Scanner keyboard = new Scanner(System.in);
- public static void main(String[] args) {
-
- // TODO 自動產生的方法 Stub
- test();
- test();
- test();
- test();
- }
- static void test() {
- System.out.println("Input a character : ");
- String num=keyboard.nextLine();
- switch(num)
- {
- case"a":
- case"b":
- System.out.println("You entered a or b");
- break;
- case"x":
- System.out.println("You entered x");
- break;
- case"y":
- System.out.println("You entered y");
- break;
- default:
- System.out.println("You entered something else.")
- }
- }
- }
複製代碼 |