Advertisement
therrontelford

Rock paper scissors

Nov 12th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Chap3_17Rock {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner(System.in);
  6.  
  7.         // generate random number from 0 to 2
  8.         int randomNum = (int)(Math.random() * 3);
  9.  
  10.         // prompt for user's pick and get that pick from the console
  11.         System.out.println("Scissor 0, Rock 1, Paper 2");
  12.         int yourPick = kb.nextInt();
  13.        
  14.  
  15.         // compare for each case
  16.         if (randomNum == 0 ){
  17.             if (yourPick==0)
  18.                 System.out.println("you both have scissors, it's a draw");
  19.             else if (yourPick==1)
  20.                 System.out.println("you have rock, the computer has scissors-- You win!");
  21.             else
  22.                 System.out.println("you have paper, the computer has scissors-- You lose");
  23.                
  24.         }
  25.         if (randomNum == 1){
  26.             if (yourPick==0)
  27.                 System.out.println("you have scissors, the computer has rock-- You lose");
  28.             else if (yourPick==1)
  29.                 System.out.println("you both have rock-- it's a draw");
  30.             else
  31.                 System.out.println("you have paper, the computer has rock-- You win");
  32.                
  33.         }
  34.         if (randomNum == 2){
  35.             if (yourPick==0)
  36.                 System.out.println("you have scissors, the computer has paper-- You win");
  37.             else if (yourPick==1)
  38.                 System.out.println("you have rock, the computer has paper-- you lose");
  39.             else
  40.                 System.out.println("you both have paper --it's a draw");
  41.                
  42.         }
  43.         }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement