剪刀,石头,布

package exercise_4;
import java.util.Scanner;
public class Q4_34 {
    public static void main(String[] args) {
        System.out.println("Enter a number(scissor(0),rock(1),paper(2)): ");
        Scanner input = new Scanner(System.in);
        int []count = new int[1000000];
        int i = 0;
        while(true){
            int inputans=input.nextInt();
            int ans=(int)(3*Math.random());
            System.out.println("The computer is "+ans);
            if(inputans-ans==1||inputans-ans==-2){
                count[i]=0;
                if(i>1){
                    if(count[i]==count[i-1]&&count[i-1]==count[i-2]){
                        System.out.println("You are win!");
                        break;
                        }
                    }
                }
            else if(inputans-ans==-1||inputans-ans==2){
                count[i]=1;
                if(i>1){
                    if(count[i]==count[i-1]&&count[i-1]==count[i-2]){
                        System.out.println("The computer is win!");
                        break;
                        }
                    }
                }
            else
                count[i]=2;
        i++;
        }
        
    }
}//连续赢两次算赢,用堆很快

 

posted @ 2012-09-22 09:45  myth_HG  阅读(189)  评论(0编辑  收藏  举报