0

So I m new to programming and java, like really new. Anyway, I am trying to write a "guessing a number" game. I want to set this random number's range between 1000 to 10000 as you can see in the code. The gamer can guess an integer and if correct then game over, if-else then guesses again, also the game would tell the gamer if it's too small or too big. But I encountered a problem it says: "Incompatible operand types Random and int" I know what that means but how can I solve it tho?... Here is the code:

import java.util.Random;
import java.util.Scanner;
public class Game {
    public static void main(String[] args) {
        Random rnd = new Random((10000-1000)+1000);
        Scanner scanner = new Scanner(System.in);
        int guess = scanner.nextInt();
        System.out.println("Please enter your number");
        if(rnd = guess) {
            System.out.println("You are right!");
        }
        else {
            System.out.println("You are wrong try again!");
        }
    }
}
h0r53
  • 3,034
  • 2
  • 16
  • 25
  • You'll need to call `nextInt()` on the `rnd` object to get a random value. And don't pass anything to the `new Random()` constructor, because it is a `seed` you are passing, causing all the "random" values to appear in the same order every time you restart your game. – Ivar Aug 12 '21 at 23:43
  • Node that `rnd = guess` is an assignment, not a condition, and as such it will have adverse effects in your code. You want `rnd == guess` for a conditional. – h0r53 Aug 12 '21 at 23:44
  • Hint: an instance of `Random` is a Random Number **Generator** not a random number. You need to call a method on the RNG to generate a random number. – Stephen C Aug 12 '21 at 23:45

0 Answers0