Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //Importing Scanner
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String player1, player2; // Assigns players to strings
- String p1Select, p2Select;
- String Rock = "ROCK";
- String Paper = "PAPER";
- String Scissors = "SCISSORS";
- System.out.println("Player 1, please type either rock, paper, or scissors.");
- player1 = input.nextLine();
- p1Select = player1.toUpperCase();
- System.out.println("Player 2, please type either rock, paper, or scissors.");
- player2 = input.nextLine();
- p2Select = player2.toUpperCase();
- if (!(p1Select.equals(Rock) || p1Select.equals(Paper) || p1Select.equals(Scissors)) &&(!(p2Select.equals(Rock) || p2Select.equals(Paper) || p2Select.equals(Scissors)))){System.out.println("Both players gave an invalid input");}
- else if (!(p1Select.equals(Rock) || p1Select.equals(Paper) || p1Select.equals(Scissors))) {
- System.out.println("Player 1 made an invalid input!");
- }
- else if (!(p2Select.equals(Rock) || p2Select.equals(Paper) || p2Select.equals(Scissors))) {
- System.out.println("Player 2 made an invalid input!");
- }
- else if (p1Select.equals(p2Select)) {
- System.out.println("It's a tie!");
- } else if (p1Select.equals(Rock)) {
- if (p2Select.equals(Paper)) {
- System.out.println("Player 2 Wins!");
- } else
- System.out.println("Player 1 Wins!");
- } else if (p1Select.equals(Scissors)) {
- if (p2Select.equals(Rock)) {
- System.out.println("Player 2 Wins!");
- } else
- System.out.println("Player 1 Wins!");
- } else if (p1Select.equals(Paper)) {
- if (p2Select.contentEquals(Scissors)) {
- System.out.println("Player 2 Wins!");
- } else
- System.out.println("Player 1 Wins!");
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement