Hi,
Can anyone tell me how to tweak my code so it will only generate a random number between 0 and the number input by user?
Here's the code:
import java.util.Random;
import java.io.*;
public class RandomNumPicker
{
public static void main(String[] args)throws IOException
{
BufferedReader stdin = new BufferedReader
(new InputStreamReader(System.in));
int num;
Random rand = new Random();
System.out.print("Enter a number to choose a random number from: ");
num = Integer.parseInt(stdin.readLine());
int result = (int) (rand.nextInt());
System.out.print("The random number is: " + result);
}
}
Here's a sample run:
Enter a number to choose a random number from: 100
The random number is: 664075476
Thank you