Random Number Generator with User Input
Hi,
I'm new to Java and I'm making a really simple random number generator, but I also want for the user to be able to choose the maximum number e.g. Random Number between 1-100, but the problem is I'm not sure of how to say it's an integer field, and I know that java is probably expecting that it'd be like 3 * hello which wouldn't work. Currently I've got the code;
Code:
import java.util.Scanner;
public class ChoiceofRandomNumber
{
public static void main(String[] args)
{
Scanner r = new Scanner(System.in);
System.out.println("What's the Maximum Number you Want to be Possible?");
String name = r.nextLine();
System.out.println((int) (Math.random() * r) +1);
}
}
I'm guessing that this'll be a really easy fix but I'm not exactly sure where to go. Thanks for your help.