0

I'm very very new to Java. I got stuck in this error where it states:

The constructor Scanner() is undefined

and

The method nextInt(int) in the type Scanner is not applicable for the arguments (InputStream).

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

public class NumberGenerator
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner();
        Random randomNumber = new Random();
        System.out.println("Please enter the maximum value: ");
        int maxValue = input.nextInt(System.in);
        for (int counter = 1; counter <= 1; counter++)
        {
            int number = randomNumber.nextInt(maxValue);
            System.out.println("Your random number is: " + number);
        }
    }
}

As you may be able to see, I'm very new and I really appreciate your help.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Eric Kim
  • 21
  • 1
  • 2

2 Answers2

1

You need to specify what the scanner is supposed to read from. I assume you want it to read from the console, in which case you would want to write:

Scanner input = new Scanner(System.in);

Also, nextInt() does not take parameters. Change it to:

int maxValue = input.nextInt();
randers
  • 5,031
  • 5
  • 37
  • 64
1

The answer to both of your problems is here https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html. The Scanner class has only constructors that require arguments and the nextInt method either takes no argument or an int.

Advice: Googling " javadoc" is a good habit.

Hatim Khouzaimi
  • 515
  • 4
  • 11