Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class gameRPS1
- {
- public static void main(String[] args)
- {
- private final int ROUNDS = 3;
- private int roundCount = 0;
- //creat instance of scanner
- Scanner keyboardIn = new Scanner(System.in);
- //declare variables
- int userChoice;
- while(roundCound < ROUNDS){
- roundCount++;
- System.out.println("Make Your Choice:\n 1 Rock\n 2 Paper\n 3 Cissors\n ");
- userChoice = keyboardIn.nextInt();
- if(userChoice == 1 ){
- System.out.println("Rock is Your Choice");
- if(userChoice == 2 )
- System.out.println("Paper is Your Choice");
- if(userChoice == 3 )
- System.out.println(" Scissors is Your Choice");
- }
- if(userChoice > 3 || userChoice < 0 ){
- System.out.println("Invalid Choice Please Select Any Of The Above");
- }
- else
- {
- System.out.println();
- }
- String [] arr = {"Rock", "Paper", "Scissors"};
- Random compChoice = new Random();
- int select = compChoice.nextInt(arr.length);
- System.out.println("Computer choice is : " + arr[select]);
- if(userChoice == 2 && arr[select] == "Rock" ||userChoice == 1 && arr[select] == "Scissors" || userChoice == 3 && arr[select] == "Paper"){
- System.out.print("YOU WIN WELL DONE!!!");
- }
- if(userChoice == 3 && arr[select] == "Rock" ||userChoice == 2 && arr[select] == "Scissors" || userChoice == 1 && arr[select] == "Paper"){
- System.out.print("Ooops You Lost!!!");
- }
- else if(userChoice == 2 && arr[select] == "Paper" ||userChoice == 1 && arr[select] == "Rock" || userChoice == 3 && arr[select] == "Scissors"){
- System.out.println("It a tie");
- }
- else
- System.out.println(" Play Again");
- }
- System.out.println("GAME OVER");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement