I'm making a guessing game where the user sets the maximum number and that number is used for the range for the random number generator, but every time I test my program it outputs 0. I'm not sure why.
import java.util.Scanner;
import java.util.Random;
public class GuessingGame {
public static Scanner scan = new Scanner (System.in);
public static Random random = new Random();
public static int answer;
public static int maxNumber;
public static int minNumber = 0;
public static void main (String [] args ){
System.out.println("Welcome to the Guessing Game.");
System.out.println("Enter the maximum number.");
int maxNumber = scan.nextInt();
System.out.println(answer); //Remove after testing
}
public static int newGame(Random random) {
int randNumber;
int range = maxNumber - minNumber;
randNumber = random.nextInt(range);
answer = randNumber;
return answer;
}
Aucun commentaire:
Enregistrer un commentaire