Simple Rock Paper Scissors Game(Java)




Simple Rock Paper Scissors game with JAVA language :

Code:

import java.util.Random;
import java.util.Scanner;
// Rock Paper Scissor game in java
// Sk Elaf Ahmed
public class RockPaper {
    public static void main(String[] args) {
        //Rock = 0   Paper = 1   Scissor = 2
       Scanner sc = new Scanner(System.in);
       int playerScore = 0compScore = 0;
       
       for(int i =0i<3i++){
           System.out.println("Enter a number Rock = 0   Paper = 1   Scissor = 2");
           int userIn = sc.nextInt();
           Random random = new Random();
           int comIn = random.nextInt(3);
           System.out.println("You choose " + userIn);
           System.out.println("Computer choose " + comIn);

        if(comIn == userIn){
            System.out.println("Draw, no one wins, both scores are same");
        }
        else if(comIn==0 && userIn==1 || comIn== 2 && userIn == 0 || userIn== 2 && comIn== 1 ){
            playerScore += 1;
            System.out.println("You win, great job");
        } else {
            compScore += 1;
            System.out.println("Computer win, try hard buddy");
        }
       }
       if(compScore>playerScore){
           System.out.println("Computer win this time!");
       }
       else if(compScore==playerScore){
           System.out.println("No one wins this time!");
       }
       else{
           System.out.println("You win, great work!");
       }
       sc.close();
    }
}






Here you can enter your choices and see the results, after 3 rounds you can see who wins.



Comments

Popular posts from this blog

C program to find the greatest of three numbers with user input.

How to add to integers in C programming

Check whether a character Vowel or Consonant