- import java.util.Scanner;
- public class Ch01 {
- public static void main(String[] args) {
- while(true)
- {
- Scanner s=new Scanner(System.in);
- String answer;
- System.out.println("請問豬有幾隻腳?");
- System.out.print("請作答: ");
- answer=s.nextLine();
- switch(answer)
- {
- case "A":
- case "a":
- case "1":
- System.out.println("用跳的嗎?");
- break;
- case "B":
- case "b":
- case "2":
- System.out.println("沒吃過豬肉也看過豬走路!");
- break;
- case "C":
- case "c":
- case "3":
- System.out.println("你是豬啊!");
- break;
- case "D":
- case "d":
- case "4":
- System.out.println("答對!");
- break;
- default:
- System.out.println("輸入錯誤!");
- }
- }
- }
- }
複製代碼 |