why does my code have an error: public class Randomizer { public static int nextInt() {…
- User
why does my code have an error: public class Randomizer { public static int nextInt() { int randInt1 = (int)(Math.random()(11)+ 1); while (randInt1 > 10 || randInt1 < 1) { randInt1 = (int)(Math.random()(11)+ 1); } return randInt1; }
codepublic static int nextInt(int min, int max) { int randInt2 = (int)(Math.random()*(max + 1) + min); while(randInt2 > max || randInt2 < min) { randInt2 = (int)(Math.random()*(max + 1) + min); } return randInt2; }}import java.util.Scanner;
public class RockPaperScissors { private static final String USER_PLAYER = "User wins!"; private static final String COMPUTER_PLAYER = "Computer wins!"; private static final String TIE = "Tie";
codepublic static String getWinner(String user, String computer) { if(user.equals(computer)) { return TIE; } else if(user.equals("rock")) { if(computer.equals("scissors")) { return USER_PLAYER; } else(computer.equals("paper")) { return COMPUTER_PLAYER; } } else if(user.equals("paper")) { if(computer.equals("scissors")) { return COMPUTER_PLAYER; } else(computer.equals("rock")) { return USER_PLAYER; } } else(user.equals("scissors")) { if(computer.equals("paper")) { return USER_PLAYER; } else(computer.equals("rock")) { return COMPUTER_PLAYER; } } public static void main(String[] args) { Scanner input = new Scanner(System.in); while(true) { int random = Randomizer.nextInt(1,3); String computerMove = ""; if(random = 1) { computerMove == "rock"; } else if { computerMove == "paper"; } else { computerMove == "scissors"; } System.out.println("Enter your choice"); String userMove = input.nextLine(); if(userMove.equals("") { System.out.println("Thanks for playing"); break; } else { System.out.println("User:" + userMove); System.out.println("Computer:" + computerMove); System.out.println(getWinner(userMove.toLowerCase(), computerMove.toLowerCase())); } } } - Assistant