猜拳游戏改良版

经过改良,现在写了一个更为高效的Java猜拳游戏,代码如下:

import java.util.*;
public class caiquanxin
{
    public static void main(String[] agrs)
    {
        String first1="拳头",first2="拳头";
        Scanner input=new Scanner(System.in);
        int computer=(int)(Math.random()*3)+1;
        System.out.println("*****猜拳游戏*****");
        System.out.println("请出拳(1石头 2剪刀 3布)");
        int person=input.nextInt();

         switch(person)
         {
            case 1:first1="石头";
                break;
            case 2:first1="剪刀";
                break;
            case 3:first1="布";
                break;
         }


        switch(computer)
         {
            case 1:first2="石头";
                break;
            case 2:first2="剪刀";
                break;
            case 3:first2="布";
                break;
         }

        if(person==computer)
            System.out.println("平局,你和电脑都出"+first1);
        else if(person==1&&computer==2||person==2&&computer==3||person==3&&computer==1)
            System.out.println("你出:"+first1+" 电脑出:"+first2+" 恭喜你,你赢了");
        else
            System.out.println("你出:"+first1+" 电脑出:"+first2+" 很遗憾,你输了");
            }
        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值