0% found this document useful (0 votes)
12 views1 page

Rock Paper Scissors Java

code for rock paper scissors game in java code

Uploaded by

kamila gregusova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Rock Paper Scissors Java

code for rock paper scissors game in java code

Uploaded by

kamila gregusova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// rock, paper, scissors

System.out.println("write 'stop' to end the game.");


String input=" ";
do {
System.out.println("Rock, Paper, Scissors shoot!");
Scanner sc = new Scanner(System.in);
input = sc.nextLine();
String[] words = {"rock", "paper", "scissors"};
Random random = new Random();
int randomIndex = random.nextInt(words.length);
String word = words[randomIndex];
System.out.println(word);
if (word.equals(input)) {
System.out.println("It's a tie! Let's play again!");
}
if (input.equals("scissors") && word.equals("paper")) {
System.out.println("You won!");
}
if (input.equals("scissors") && word.equals("rock")) {
System.out.println("You lost!");
}
if (input.equals("rock") && word.equals("scissors")) {
System.out.println("You won!");
}
if (input.equals("rock") && word.equals("paper")) {
System.out.println("You lost!");
}
if (input.equals("paper") && word.equals("rock")) {
System.out.println("You won!");
}
if (input.equals("paper") && word.equals("scissors")) {
System.out.println("You lost!");
}
} while (!input.equals("stop"));
System.out.println("");

You might also like