借鉴的!
import java.util.Scanner;
import java.util.Random;
public class Shitou
{
public static void main(String[] args)
{
Random ran=new Random();
Scanner sca=new Scanner(System.in);
System.out.println("请选择石头剪刀布:0.石头,1.剪刀,2.布");
int a=0;
int b=0;
int c=0;
int d=a+b+c;
for(;;)
{
int player=sca.nextInt();
int s=ran.nextInt(3);
import java.util.Random;
public class Shitou
{
public static void main(String[] args)
{
Random ran=new Random();
Scanner sca=new Scanner(System.in);
System.out.println("请选择石头剪刀布:0.石头,1.剪刀,2.布");
int a=0;
int b=0;
int c=0;
int d=a+b+c;
for(;;)
{
int player=sca.nextInt();
int s=ran.nextInt(3);
if(player==0&&s==1 || player==1&&s==2 || player==2&&s==0)
{
a++;
System.out.println("你赢啦");
}
if(player==s)
{
b++;
System.out.println("平局");
}
if(player==0&&s==1 || player==1&&s==0 || player==2&&s==1)
{
c++;
System.out.println("你输啦");
}
if(player>2&&player!=9)
{
System.out.println("输入错误,请重新输入");
}
if(player==9)
{
d=a+b+c;
System.out.println("游戏结束");
System.out.println("你一共进行了:"+d+"次游戏");
System.out.println("你一共赢了:"+a+"次");
System.out.println("你一共平局了:"+b+"次");
System.out.println("你一共输了:"+c+"次");
break;
}
}
}
}