一个剪刀石头的问题,但是运行输入的时候有时会报如下的错误。不明白是怎么回事,望指教!第十七行是c.ran = comdata[ran.nextInt()%3];
import java.util.Scanner;
import java.util.Random;
public class text{
public static void main (String []args){
Person p = new Person();
com c = new com();
Scanner scan = new Scanner(System.in);
Random ran = new Random ();
tool t = new tool();
int i;
int []comdata = {0,2,5};
System.out.println("0 is stone\t2 is scissors\t5 is cloth");
System.out.println("PLEASE INPUT");
for(i=1;i<=3;i++){
p.into = scan.nextInt();
c.ran = comdata[ran.nextInt()%3];
t.cam(p,c);
}
}
}
class Person{
int into;
}
class com{
int ran;
}
class tool{
int n ;
public void cam(Person p , com c ){
if (p.into == 0 && c.ran ==2)
{
System.out.println("===============================");
System.out.println("\tcomputar is"+c.ran);
System.out.println ("\tYOU WIN!");
n++;
}
else if(p.into == 2 && c.ran ==5){
System.out.println("===============================");
System.out.println("\tcomputar is"+c.ran);
System.out.println ("\tYOU WIN!");
n++;
}
else if(p.into == 5 && c.ran ==0){
System.out.println("===============================");
System.out.println("\tcomputar is"+c.ran);
System.out.println ("\tYOU WIN!");
n++;
}
else if (p.into == c.ran ){
System.out.println("===============================");
System.out.println("\tcomputar is"+c.ran);
System.out.println("\tYOU ARE THE SAME");
}
else{
System.out.println("===============================");
System.out.println("\tcomputar is"+c.ran);
System.out.println("\tYOU LOSE");
}
}
}