This is a program I wrote to play rock paper scissors!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /* Kenneth Schrom partner project, done by myself Rock Paper Scissors */ import java.util.Scanner; //imports scanner for keyboard input public class RockPaperScissor //name of program { public static void main(String[] args) { Scanner input = new Scanner(System.in); /* variables for the rock paper scissor game scissor = 0; rock = 1; paper = 2; */ int computer = (int)(Math.random() * 3); //random number generator for 0 - 2 System.out.println("Choose the number for Rock (1), Paper (2) or Scissor (0)!"); //prompt to choose rock, papor or scissor int player = input.nextInt(); if (computer == 0) { if (player == 0) System.out.print("The computer chose " + computer + " and you chose " + player + " - it's a draw."); else if (player == 1) System.out.print("The computer chose " + computer + " and you chose " + player + " - you won!"); else if (player == 2) System.out.print("The computer chose " + computer + " and you chose " + player + " - you lost. Better luck next time!"); } else if(computer == 1) { if (player == 1) System.out.print("The computer chose " + computer + " and you chose " + player + " - it's a draw."); else if (player == 2) System.out.print("The computer chose " + computer + " and you chose " + player + " - you won!"); else if (player == 0) System.out.print("The computer chose " + computer + " and you chose " + player + " - you lost. Better luck next time!"); } else if (computer == 2) { if (player == 2) System.out.print("The computer chose " + computer + " and you chose " + player + " - it's a draw."); else if (player == 0) System.out.print("The computer chose " + computer + " and you chose " + player + " - you won!"); else if (player == 1) System.out.print("The computer chose " + computer + " and you chose " + player + " - you lost. Better luck next time!"); } } } |
Return to Main Page.