What is Rock Paper Scissor game?
Rock paper scissor game is hand game played between two players ,in each player at the same time forms one of three shapes.
Rock Paper Scissor game in java
When we want to rock paper scissor game with computer what we do for this
we make a computer program with the help of java.
LETS START CODING
We use while loop to play game five times after that calculate the points of both user and computer then print the winner and there points.
In this game we take 0 for stone, 1 for paper, 2 for scissor.
import java.util.Random
We have to import random module to generate the computer choice. simply ,we have to write import java.util.Random; to import random module.
Taking user input
For taking input from the user we have to import import java.util.Scanner;
After that we have to write System.out.println("Enter your play:");
MAKING COMPUTER CHOICE
For computer choice we have to write Random r=new Random();
GAME CONDITION
For game condition and determine winner we have to use IF ,ELSE condition .
When user input is equal to 0(rock) and computer input is 1(scissor) then user wins.
When user input is equal to 1(scissor) and computer input is 2(paper) then user wins.
When user input is equal to 2(paper) and computer input is 0(rock) then user wins.
When user input is equal to 0(rock) and computer input is 1(paper) then computer wins.
When user input is equal to 1(scissor) and computer input is 0(rock) then computer wins.
When user input is equal to 2(paper) and computer input is 1(scissor) then computer wins.
When user input is equal to computer input then display "Its tie".
When user enter other input then display "enter valid number".
After while loop complete we calculate the points of user and computer and print the winner and there points.
HERE ARE THE CODE
OUTPUT