• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

微笑_199303

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

java实现猜拳游戏

package com.utils;

import java.util.Scanner;

public class Scissors_Stone_Cloth {
public static void main(String[] args) {
while (true) {
System.out.println("----猜拳游戏开始----");
System.out.println("请按要求输入:1.石头 2.剪刀 3.布");
String marks = "石头";
String marks2 = "石头";

while (true) {
Scanner in = new Scanner(System.in);
int person = in.nextInt();
if (person != 1 && person != 2 && person != 3) {
System.out.println("请正确出拳,1,2,3");
break;
}
int computer = (int) (Math.random() * 3 + 1);

switch (person) {
case 1:
marks = "石头";
break;
case 2:
marks = "剪刀";
break;
case 3:
marks = "布";
break;
}
switch (computer) {
case 1:
marks2 = "石头";
break;
case 2:
marks2 = "剪刀";
break;
case 3:
marks2 = "布";
break;
}
if (computer == person) {
System.out.println("您出的是" + marks + "\n电脑出的是" + marks2 + "\n-----平局=_=");
break;
} else if ((person == 1 && computer == 2) || (person == 2 && computer == 3) || (person == 3 && computer == 1)) {
System.out.println("您出的是" + marks + "\n电脑出的是" + marks2 + "\n-----恭喜您,您赢了!^_^");
break;
} else {
System.out.println("您出的是" + marks + "\n电脑出的是" + marks2 + "\n-----对不起,您输了!QAQ");
break;
}

}
}

}

}

posted on 2021-05-18 10:29  微笑_199303  阅读(235)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3