Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Chap3_17Rock {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- // generate random number from 0 to 2
- int randomNum = (int)(Math.random() * 3);
- // prompt for user's pick and get that pick from the console
- System.out.println("Scissor 0, Rock 1, Paper 2");
- int yourPick = kb.nextInt();
- // compare for each case
- if (randomNum == 0 ){
- if (yourPick==0)
- System.out.println("you both have scissors, it's a draw");
- else if (yourPick==1)
- System.out.println("you have rock, the computer has scissors-- You win!");
- else
- System.out.println("you have paper, the computer has scissors-- You lose");
- }
- if (randomNum == 1){
- if (yourPick==0)
- System.out.println("you have scissors, the computer has rock-- You lose");
- else if (yourPick==1)
- System.out.println("you both have rock-- it's a draw");
- else
- System.out.println("you have paper, the computer has rock-- You win");
- }
- if (randomNum == 2){
- if (yourPick==0)
- System.out.println("you have scissors, the computer has paper-- You win");
- else if (yourPick==1)
- System.out.println("you have rock, the computer has paper-- you lose");
- else
- System.out.println("you both have paper --it's a draw");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement