java实现猜拳游戏
作者:我是很棒的啊 时间:2023-08-04 04:23:52
本文实例为大家分享了java实现猜拳游戏的具体代码,供大家参考,具体内容如下
package com.farsight.session7;
import java.util.Scanner;
/**
* 根据输入的数字,判断数组strs的值 然后进行逻辑判断
*/
public class 猜拳 {
public static void main(String[] args) {
String[] strs = { "石头", "剪刀", "布" };
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的选择:(0.石头 1.剪刀 2.布)");
int input = sc.nextInt();
String input_str = strs[input];
System.out.println("您输入的是:" + input_str);
int ran = (int) (Math.random() * 3);
String sys_str = strs[ran];
System.out.println("系统输出的是:" + sys_str);
if (input_str.equals(sys_str)) {
System.err.println("你们是平局");
} else if (input_str == "石头" && sys_str == "剪刀" || input_str == "剪刀"
&& sys_str == "布" || input_str == "布" && sys_str == "石头") {
System.err.println("你赢了");
} else {
System.err.println("你输了");
}
}
}
运行结果:
请输入您的选择:(0.石头 1.剪刀 2.布)
2
您输入的是:布
你赢了
系统输出的是:石头
来源:https://blog.csdn.net/chazihong/article/details/51968324
标签:java,猜拳游戏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android编程判断当前应用是否在后台运行的方法示例
2021-10-29 12:09:36
Android如何创建自定义ActionBar
2022-11-18 03:57:16
![](https://img.aspxhome.com/file/2023/6/139116_0s.gif)
理解Android中的自定义属性
2023-07-30 11:09:32
android实现获取正在运行的应用程序
2022-10-14 09:23:38
![](https://img.aspxhome.com/file/2023/4/139594_0s.png)
Java实现分页查询功能
2023-03-03 14:30:19
![](https://img.aspxhome.com/file/2023/3/72403_0s.jpg)
java中的FileInputStream三种read()函数用法
2021-10-27 23:01:21
![](https://img.aspxhome.com/file/2023/8/103838_0s.png)
Android开发登陆案例
2022-03-19 10:13:01
![](https://img.aspxhome.com/file/2023/3/137743_0s.png)
SpringBoot+easypoi实现数据的Excel导出
2023-04-05 12:27:19
SpringBoot中发送QQ邮件功能的实现代码
2022-09-25 10:19:59
![](https://img.aspxhome.com/file/2023/8/72648_0s.png)
详解c# 线程同步
2023-11-23 08:54:48
![](https://img.aspxhome.com/file/2023/8/94628_0s.png)
C#读写操作app.config中的数据应用介绍
2021-07-25 21:33:19
idea springboot远程debug的操作方法
2022-11-01 00:04:31
![](https://img.aspxhome.com/file/2023/8/62498_0s.png)
C#访问SqlServer设置链接超时的方法
2022-11-19 17:43:21
不可不知道的10个java谎言
2022-01-21 10:25:40
Spring注解@Scope原理及用法解析
2023-12-06 14:08:17
eclipse连接不到genymotion问题的解决方案
2022-09-05 23:26:16
![](https://img.aspxhome.com/file/2023/4/125244_0s.png)
Android调用手机摄像头拍照和录音功能
2022-10-22 15:37:16
C#实体类转换的两种方式小结
2023-08-01 21:06:45
C#装箱和拆箱原理详解
2021-12-29 16:07:26
![](https://img.aspxhome.com/file/2023/6/89736_0s.jpg)
解析springboot整合谷歌开源缓存框架Guava Cache原理
2023-11-07 13:24:23
![](https://img.aspxhome.com/file/2023/0/62030_0s.png)