Discuss / Java / 完成作业

完成作业

Topic source

杨泽塘

#1 Created at ... [Delete] [Delete and Lock User]
import java.util.Scanner;public class Main_game {    public static void main(String[] args){        Scanner scanner = new Scanner(System.in);        System.out.print("1.石头,2.剪刀,3.布)请输入数字:");        int input = scanner.nextInt();        String play = switch (input){            case 1->"石头";            case 2->"剪刀";            case 3->"布";            default -> "输入错误";        };        System.out.println("你出了:"+play);        int random = 1 + (int) (Math.random() * 3); //电脑随机出123        String commput = switch (random){            case 1->"石头";            case 2->"剪刀";            case 3->"布";            default -> "";        };        System.out.println("电脑出了:"+commput);        if (play == commput){System.out.print("平局");}        else if (play=="石头"&&commput=="布"||play=="剪刀"&&commput=="石头"||play=="布"&&commput=="剪刀"){System.out.print("电脑赢了");}        else {System.out.print("你赢了");};

  • 1

Reply