package com.itranswarp.learnjava; import java.util.Scanner; /** * switch实现石头/剪子/布并判断胜负 */ public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("please choice:"); System.out.println(" 1: Rock"); System.out.println(" 2: Scissors"); System.out.println(" 3: Paper"); // 用户输入: int choice = 0; choice = scanner.nextInt(); // 计算机随机数 1, 2, 3: int random = 1 + (int) Math.random() * 3; switch (Math.abs(choice-random)) { case 0 -> System.out.println("tie"); case 1 -> System.out.println("you lose"); case 2 -> System.out.println("you win"); // TODO: } } }
Sign in to make a reply
名字已经上交给国家