Java语言程序设计(基础篇)第十版 编程练习题 3.17(游戏: 剪刀 ,石头,布)


public class Game {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        java.util.Scanner input = new java.util.Scanner(System.in);

        System.out.println("scissor (0), rock(1), paper (2)");
        int gamePlayer = input.nextInt();


        int computer = (int)(Math.random() * 3);

        if(computer == 0)
        {
            if( gamePlayer==0)
                System.out.println("The computer is scissor . you are scissor too. It is a draw");
            else if(gamePlayer == 1)
                System.out.println("The computer is scissor . you are rock. you won!");
            else 
                System.out.println("The computer is scissor . you are paper. you lose");

        }
        else if(computer == 1)
        {
            if(gamePlayer ==0)
                System.out.println("The computer is rock. you are scissor. you lose");
            else if(gamePlayer == 1)
                System.out.println("The computer is rock. you are rock too. It is a darw");
            else 
                System.out.println("The computer is rock. you are paper. you win!");
        }
        else
        {
            if(gamePlayer == 0)
                System.out.println("The computer is paper.you are scissor. you won!");
            else if(gamePlayer == 1)
                System.out.println("The computer is paper. you are rock. you lose!");
            else
                System.out.println("The computer is paper. you are paper too. It is a draw");
        }

    }

}

你可能感兴趣的:(java)