Java Reference
In-Depth Information
");
printWinner(yourHand, 3);
break;
default:
System.out.print("You cheated! ");
printWinner(yourHand, myHand);
}
}
private static void printWinner(int yourHand, int
winningHand) {
if (yourHand == winningHand) {
System.out.println("You win!");
}
else {
System.out.println("I win!");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Let's Play Rock, Paper,
Scissors");
System.out.println(" Enter 1 (Rock)");
System.out.println(" Enter 2 (Paper)");
System.out.println(" Enter 3 (Scissors)");
System.out.print("> ");
int playerHand = input.hasNextInt()
? input.nextInt() : -99;
int computerHand = (int)(3*Math.random()) + 1;
System.out.print("Your hand: (" + playerHand + ")
");
getHand(playerHand);
System.out.print("My hand: (" + computerHand + ")
");
Search WWH ::




Custom Search