Java:人机猜拳(简单版)

//输入石头剪子布拼音(捂脸   三次结束,显示输赢次数

import java.util.*;
public class caiquan {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String[] bags={"shitou","jianzi","bu"};
        int count=0;
        int win=0,lose=0,equal=0;
        while(count<3) {
            System.out.print("enter your fine: ");
            String t1=input.nextLine();
            int randomnumber=(int)(Math.random()*3);
            if(bags[0].equals(bags[randomnumber]))
            {
                if(t1.equals(bags[0]))
                    equal++;
                else if(t1.equals(bags[1]))
                    lose++;
                else
                    win++;
                System.out.println(bags[randomnumber]);
            }
            else if(bags[1].equals(bags[randomnumber]))
            {
                if(t1.equals(bags[0]))
                    win++;
                else if(t1.equals(bags[1]))
                    equal++;
                else
                    lose++;
                System.out.println(bags[randomnumber]);
            }
            else
            {
                if(t1.equals(bags[0]))
                    lose++;
                else if(t1.equals(bags[1]))
                    win++;
                else
                    equal++;
                System.out.println(bags[randomnumber]);
            }
            count++;
            System.out.println("win "+win+" lose "+ lose+" equal "+ equal);
        }
        if(win>lose)
            System.out.println("you are win");
        else
            System.out.println("you are lose");
}
}





你可能感兴趣的:(java基础篇)