HI I was wondering if you can help me with this random number program.
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
class GuessAgain {
public static void main(String args[]) {
Scanner myScanner = new Scanner(System.in);
int numGuesses = 0;
int randomNumber = new Random().nextInt(10) + 1;
out.println(" ************ ");
out.println("Welcome to the Guessing Game");
out.println(" ************ ");
out.println();
out.print("Enter an int from 1 to 10: ");
int inputNumber = myScanner.nextInt();
numGuesses++;
while (inputNumber != randomNumber) {
out.println();
out.println("Try again...");
out.print("Enter an int from 1 to 10: ");
inputNumber = myScanner.nextInt();
numGuesses++;
}
out.print("You win after ");
out.println(numGuesses + " guesses.");
}
}
The problem I am having is with this line int randomNumber = new Random().nextInt(10) + 1;
Why do we need to add a nextInt() method to it, I don't understand? Was this int randomNumber = new Random(10 + 1);
enough?
thanks