Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- *
- * @author Neel
- */
- public class RPS
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- String playerA = "";
- String playerB = "";
- boolean playAgain = false;
- System.out.print("Player 1: Enter R (rock), (P) Paper, (S) Scissors: ");
- playerA = in.nextLine();
- do
- {
- if(playerA.equalsIgnoreCase("R"))
- {
- System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
- playerB = in.nextLine();
- if(playerB.equalsIgnoreCase("R"))
- {
- System.out.println("Rock ties rock, it's a tie!");
- }
- else if(playerB.equalsIgnoreCase("P"))
- {
- System.out.println("Paper beats rock, Player 2 wins!");
- }
- else
- {
- System.out.println("Rock beats scissors, Player 1 wins!");
- }
- }
- else if(playerA.equalsIgnoreCase("P"))
- {
- System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
- playerB = in.nextLine();
- if (playerB.equalsIgnoreCase("R"))
- {
- System.out.println("Paper beats rock, Player 1 wins!");
- }
- else if (playerB.equalsIgnoreCase("P"))
- {
- System.out.println("Paper ties paper, it is a tie!");
- }
- else
- {
- System.out.println("Scissors cut paper, Player 2 wins!");
- }
- }
- else if(playerB.equalsIgnoreCase("S"))
- {
- System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
- playerB = in.nextLine();
- if (playerB.equalsIgnoreCase("R"))
- {
- System.out.println("Rock beats scissors, Player 2 wins!");
- }
- else if (playerB.equalsIgnoreCase("P"))
- {
- System.out.println("Scissors beat paper, Player 1 wins!");
- }
- else
- {
- System.out.println("Scissors ties scissors, it is a tie!");
- }
- }
- else
- {
- System.out.println("You entered an invalid value, please try again!");
- }
- }while (playAgain);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement