import java.util.Scanner;
/**
* およそ神
* 输入123猜拳游戏
*/
public class demo05 {
public static void main(String[] args) {
while (true) {
int bot = (int) (Math.random() * 3) + 1;
System.out.println("输入123开始猜拳");
Scanner scanner = new Scanner(System.in);
int sc = 0;
try {
sc = scanner.nextInt();
} catch (Exception e) {
System.out.println("您的输入错误,请重新输入");
continue;
}
if (bot == 1 && sc == 2 || bot == 2 && sc == 3 || bot == 3 && sc == 1) {
System.out.println("U win !");
while (true) {
System.out.println("您是否想继续玩,请回答yes或者no");
String s = scanner.next();
if (s.equalsIgnoreCase("yes")) {
System.out.println("游戏继续进行!");
break;
} else if (s.equalsIgnoreCase("no")) {
System.out.println("游戏结束,再见");
return;
} else {
System.out.println("您的输入有误,请重新输入");
}
}
} else if (bot == sc) System.out.println("平局!");
else System.out.println("电脑赢了!");
}
}
}
最终实现效果如下: