HW3.17

时间:2023-03-09 22:38:53
HW3.17

HW3.17

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("scissor(0), rock(1), paper(2): ");
         int playerValue = input.nextInt();

         input.close();

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

         String player = "";
         if(playerValue == 0)
             player = "scissor";
         else if(playerValue == 1)
             player = "rock";
         else if(playerValue == 2)
             player = "paper";

         String computer = "";
         if(computerValue == 0)
             computer = "scissor";
         else if(computerValue == 1)
             computer = "rock";
         else if(computerValue == 2)
             computer = "paper";

         if(playerValue == computerValue)
             System.out.println("The computer is " + computer + ". You are " + player + " too. It is a draw.");
         else
             System.out.print("The computer is " + computer + ". You are " + player + ". ");

         if(playerValue == 0 && computerValue == 1 || playerValue == 1 && computerValue == 2 ||
             playerValue == 2 && computerValue == 0)
             System.out.println("Computer win");
         if(playerValue == 1 && computerValue == 0 || playerValue == 2 && computerValue == 1 ||
             playerValue == 0 && computerValue == 2)
             System.out.println("You win");
     }
 }