import java.util.Scanner;/** * switch实现石头/剪子/布并判断胜负 */public class flowSwitch { public static void main(String[] args) { System.out.println("please choice:"); System.out.println(" 1: Rock"); System.out.println(" 2: Scissors"); System.out.println(" 3: Paper"); // 用户输入: Scanner sc = new Scanner(System.in); int choice = sc.nextInt(); if (choice > 3 || choice < 1){ System.out.println("input error~! Please again"); choice = sc.nextInt(); } // 计算机随机数 1, 2, 3: int random = (int) (1 + Math.random() * 3); System.out.println("random:" + random); switch (choice) { case 1 : if (random == 1){ System.out.println("Draw"); System.out.println("computer is Rock"); }else if (random == 2){ System.out.println("Player win"); System.out.println("computer is Scissors"); }else if (random == 3){ System.out.println("Player loser"); System.out.println("computer is Paper"); } break; case 2 : if (random == 1){ System.out.println("Player loser"); System.out.println("computer is Rock"); }else if (random == 2){ System.out.println("Draw"); System.out.println("computer is Scissors"); }else if (random == 3){ System.out.println("Player win"); System.out.println("computer is Paper"); } break; case 3 : if (random == 1){ System.out.println("Player win"); System.out.println("computer is Rock"); }else if (random == 2){ System.out.println("Player loser"); System.out.println("computer is Scissors"); }else if (random == 3){ System.out.println("Draw"); System.out.println("computer is Paper"); } break; } }}
Sign in to make a reply
皮塔莫拉克