package com.sxt;
import java.util.Scanner;
public class caiquan {
public static void main(String[] args) {
while (true)
{
Scanner sc=new Scanner(System.in);
System.out.println("======欢迎使用猜拳=======");
System.out.println("请输入你的选择 0:剪刀 1:石头 2:布");
int person=sc.nextInt();
int computer=(int)(Math.random()*3)+1;
String peo="人类";
String com="电脑";
switch (person)
{
case 0:
peo="剪刀";
break;
case 1:
peo="石头";
break;
case 2:
peo="布";
break;
default:
}
switch (computer)
{
case 1:
com="剪刀";
break;
case 2:
com="石头";
break;
case 3:
com="布";
break;
default:
}
if (person==0&&computer==3||person==1&&computer==0&&person==2||computer==1)
{
System.out.println("你出"+peo+",计算机出"+com+",你赢了");
break;
}
if (person==computer)
{
System.out.println("你出"+peo+",计算机出"+com+",平局!请再出拳");
}
else
{
System.out.println("你出"+peo+",计算机出"+com+",你输了请再出拳");
}
}
}
}
Java猜拳
最新推荐文章于 2024-07-12 16:26:30 发布