- import java.util.Scanner;
- public class Ch03
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int ans;
- System.out.println("<Brain Teasers>");
- System.out.println("How many legs do pigs have? 1. One leg 2. 2 legs 3. 3 legs 4. 4 legs");
- System.out.print("Your answer is: ");
- ans=s.nextInt();
- switch(ans)
- {
- case 1:
- System.out.println("Do pigs hop now?");
- break;
- case 2:
- System.out.println("Have you never seen a pig walk?");
- break;
- case 3:
- System.out.println("You're the only pig here!");
- break;
- case 4:
- System.out.println("Correct:)");
- break;
- default:
- System.out.println("Wrong input!");
- }
- }
- }
複製代碼 |