rock paper scissors java chegg code example
Example 1: rock paper scissors java
import java.util.Scanner;
public class rps2 {
public void rps2(){
Scanner sage = new Scanner(System.in);
int b;
b = 1;
System.out.println("Play again? Y(8), N(9)?");
int yes= 8, no = 9;
int input;
input = sage.nextInt();
if(input == yes){
System.out.println("Rock,Paper,Scissors!");
}else{
System.out.println("Thanks for playing!");
}
}
}
Example 2: rock paper scissors java
import java.util.Random;
public class RandomComputerPlayer implements RPSPlayer {
private final Random random;
public RandomComputerPlayer(Random random) {
this.random = random;
}
public String play() {
return CHOICES[this.random.nextInt(CHOICES.length)];
}
}