Code a rock paper scissors game with Java! 🗿 @BroCodez
Code a rock paper scissors game with Java! 🗿  @BroCodez
Uploaded December 2024 | Updated September 2026, 2 weeks ago
#java #javatutorial #javacourse

This is a coding project for beginners to help you learn how to code. We will use the following previous topics: arrays, loops, logical operators, random numbers, and string methods.

import java.util.Random;
import java.util.Scanner;

public class Main {
public static void main(String[] args){

// ROCK PAPER SCISSORS GAME

Scanner scanner = new Scanner(System.in);
Random random = new Random();

String[] choices = {"rock", "paper", "scissors"};
String playerChoice;
String computerChoice;
String playAgain = "yes";

do{
System.out.print("Enter your move (rock, paper, scissors): ");
playerChoice = scanner.nextLine().toLowerCase();

if(!playerChoice.equals("rock") && !playerChoice.equals("paper") && !playerChoice.equals("scissors")){
System.out.println("Invalid choice");
continue;
}

computerChoice = choices[random.nextInt(3)];
System.out.println("Computer choice: " + computerChoice);

if(playerChoice.equals(computerChoice)){
System.out.println("It's a tie!");
}
else if((playerChoice.equals("rock") && computerChoice.equals("scissors")) ||
(playerChoice.equals("paper") && computerChoice.equals("rock")) ||
(playerChoice.equals("scissors") && computerChoice.equals("paper"))){
System.out.println("You win!");
}
else{
System.out.println("You lose!");
}

System.out.print("Play again (yes/no): ");
playAgain = scanner.nextLine().toLowerCase();

}while(playAgain.equals("yes"));

System.out.println("Thanks for playing!");

scanner.close();
}
}
Code a rock paper scissors game with Java! 🗿Learn Java generics in 13 minutes! 📦Lets code a QUIZ GAME with C programming! 💯Matplotlib scatter plots in 6 minutes! ✨Pointers are easy! 👈Learn Java timertasks in 6 minutes! ⏲️Filtering in NumPy is easy! 🧲Code a Java compound interest calculator in 7 minutes! 💸Code a Java countdown timer in 6 minutes! ⏳Learn binary in 01000001 secondsLets create a graph using Pandas and Matplotlib! 🐼📊METHODS in Java are easy 📞
Bro Code |

Code a rock paper scissors game with Java! 🗿

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER