Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. /**
  6. *
  7. * @author Neel
  8. */
  9. public class RPS
  10. {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args)
  16. {
  17. Scanner in = new Scanner(System.in);
  18. String playerA = "";
  19. String playerB = "";
  20. boolean playAgain = false;
  21.  
  22. System.out.print("Player 1: Enter R (rock), (P) Paper, (S) Scissors: ");
  23. playerA = in.nextLine();
  24.  
  25. do
  26. {
  27. if(playerA.equalsIgnoreCase("R"))
  28. {
  29. System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
  30. playerB = in.nextLine();
  31.  
  32. if(playerB.equalsIgnoreCase("R"))
  33. {
  34. System.out.println("Rock ties rock, it's a tie!");
  35. }
  36. else if(playerB.equalsIgnoreCase("P"))
  37. {
  38. System.out.println("Paper beats rock, Player 2 wins!");
  39. }
  40. else
  41. {
  42. System.out.println("Rock beats scissors, Player 1 wins!");
  43. }
  44. }
  45. else if(playerA.equalsIgnoreCase("P"))
  46. {
  47. System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
  48. playerB = in.nextLine();
  49.  
  50. if (playerB.equalsIgnoreCase("R"))
  51. {
  52. System.out.println("Paper beats rock, Player 1 wins!");
  53. }
  54. else if (playerB.equalsIgnoreCase("P"))
  55. {
  56. System.out.println("Paper ties paper, it is a tie!");
  57. }
  58. else
  59. {
  60. System.out.println("Scissors cut paper, Player 2 wins!");
  61. }
  62. }
  63. else if(playerB.equalsIgnoreCase("S"))
  64. {
  65. System.out.print("Player 2: Enter R (rock), (P) Paper, (S) Scissors: ");
  66. playerB = in.nextLine();
  67.  
  68. if (playerB.equalsIgnoreCase("R"))
  69. {
  70. System.out.println("Rock beats scissors, Player 2 wins!");
  71. }
  72. else if (playerB.equalsIgnoreCase("P"))
  73. {
  74. System.out.println("Scissors beat paper, Player 1 wins!");
  75. }
  76. else
  77. {
  78. System.out.println("Scissors ties scissors, it is a tie!");
  79. }
  80. }
  81. else
  82. {
  83. System.out.println("You entered an invalid value, please try again!");
  84. }
  85. }while (playAgain);
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement