package Four;
import java.util.Random;
import java.util.Scanner;
public class Caiquan {
public static void main(String[] args) {
Tom1 t=new Tom1();
Scanner scanner=new Scanner(System.in);
System.out.print("请输入对局次数:");
int n=scanner.nextInt();
int []a1=new int[n];//存储玩家出拳
int []a2=new int[n];//存储电脑出拳
String []a3=new String[n];//存储输赢
for (int i=0;i<n;i++){
//获取玩家出拳
System.out.print("请出拳(0石头1剪刀2布):");
int a=scanner.nextInt();
t.jiancha(a);
a1[i]=a;
//获取电脑出拳
a2[i]=t.diannao();
//进行比较
a3[i]=t.bijiao(a1[i],a2[i]);
System.out.println("第"+(i+1)+"局:"+a3[i]);
System.out.println("你的出拳为:"+a1[i]+" "+"电脑的出拳为:"+a2[i]);
}
}
}
class Tom1{
int a1;//玩家
int a2;//电脑
//检查玩家出拳
public void jiancha(int a){
if(a>2||a<0)
System.out.println("输入错误");
else
this.a1=a;
}
//电脑出拳
public int diannao(){
Random r=new Random();
this.a2=r.nextInt(3);
return this.a2;
}
//进行比较
public String bijiao(int a1,int a2) {
if(a1==0&&a2==1||a1==1&&a2==2||a1==2&&a2==0){
return "你赢了";
} else if(a1==a2){
return "平局";
} else return "你输了";
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/63d4e39342a772c2554a4511b7c54cbc.png)