Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 15101194S
- //Import Scanner
- import java.util.Scanner;
- import java.util.Random;
- public class PaperScissorsRock
- {
- public static void main(String[] args)
- {
- //Title
- System.out.println("Rock, Paper, Scissors");
- //Scanner
- Scanner sc = new Scanner(System.in);
- //Insert Values
- System.out.print("Enter 0 for paper, 1 for scissors, or 2 for rock (-1 to quit): ");
- int Value1 = sc.nextInt();
- //Randomizer
- Random randomGen = new Random();
- // nextInt() returns a pseudo random, uniformly
- // distributed integer value between 0 (inclusive)
- // and the specified value (exclusive), therefore,
- // the following generates a random value between 0 to 2
- int Value2 = randomGen.nextInt(3);
- //Computer Output
- switch(Value2)
- {
- case 0:
- System.out.println("Computer picks paper");
- break;
- case 1:
- System.out.println("Computer picks scissors");
- break;
- case 2:
- System.out.println("Computer picks rock");
- break;
- }
- //Calculation
- if (Value1 >= 0){
- if ((Value1 == 0 && Value2 == 2) || (Value1 == 1 && Value2 == 0) || (Value1 == 2 && Value2 == 1))
- System.out.println("Player Wins");
- if ((Value1 == 0 && Value2 == 0) || (Value1 == 1 && Value2 == 1) || (Value1 == 2 && Value2 == 2))
- System.out.println("Draw");
- else
- System.out.println("Computer Wins");
- }
- //Error
- if (Value1 < 0)
- System.out.println("Invalid input.");
- //Output
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement