帮我用Java编写一个石头剪刀布小程序
时间: 2023-03-26 16:02:39 浏览: 110
(已更新)剪刀石头布微信小程序源码
5星 · 资源好评率100%
你好,我是 C 知道。以下是 Java 编写的石头剪刀布小程序:
import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] options = {"石头", "剪刀", "布"};
int computerOption = (int) (Math.random() * 3);
System.out.print("请输入你的选项(-石头,1-剪刀,2-布):");
int userOption = input.nextInt();
System.out.println("你出了" + options[userOption] + ",电脑出了" + options[computerOption]);
if (userOption == computerOption) {
System.out.println("平局");
} else if ((userOption == && computerOption == 1) || (userOption == 1 && computerOption == 2) || (userOption == 2 && computerOption == )) {
System.out.println("你赢了");
} else {
System.out.println("电脑赢了");
}
}
}
阅读全文