I am trying to write a program that prompts the user to enter a number between 1 to 1000.Randomly generating the users input between 1 to 1000. I am using the Random generator = new Random () method. I am having trouble implementing the for loop.Can someone help?
public static void main(String[] args)throws IOException{ Random generator = new Random(1000); int temp = 0; System.out.println(" Enter Integers :"); //prompt user
I was thinking I might need a loop, so when the user inputs a number the loop will hold that number. I was thinking it will breakout the loop when it has reach the users inputed number. Giving the random numbers between 1 to 1000. What do you suggest I do? Thanx
Ernest Friedman-Hill
author and iconoclast
Marshal
Originally posted by Joe suave: I was thinking I might need a loop, so when the user inputs a number the loop will hold that number. I was thinking it will breakout the loop when it has reach the users inputed number. Giving the random numbers between 1 to 1000. What do you suggest I do? Thanx
I'm sorry, I read this four or five times and I still can't figure out what you want this program to do. How about this: can you show me a fictitious interactive session with this program? I.e., the prompts, what the user types, what gets printed. Then maybe I'd understand. I've only had one beer tonight but I'm tired so maybe it was enough to addle my brain!
Alan Green
Greenhorn
Joined: Sep 07, 2003
Posts: 17
posted
0
Lets say the user enters the number 12. I am trying to Random Generate 12 numbers between 1 to 1000. Like this........Enter a Integer 12 Output 100 56 725 32 552 5 366 321 411 945 200 201
Ernest Friedman-Hill
author and iconoclast
Marshal
Ah, OK, well, that's easy enough. You wrote in your original message
The loop control is basically correct; you want to change "x" to "next" so that the upper limit of the loop is the number the user typed in. Then, give the loop a body (a set of "{}" curly braces) and inside the body, do two things: call generator.nextInt() to get a new random number, and then print it.
Adrian Yan
Ranch Hand
Joined: Oct 02, 2000
Posts: 688
posted
0
I've only had one beer tonight but I'm tired so maybe it was enough to addle my brain!
admit it! You are a light weight!!!
Alan Green
Greenhorn
Joined: Sep 07, 2003
Posts: 17
posted
0
I don't understand how the braces are going to be . Is it going to be a while statement? class assmt2 {
public static void main(String[] args)throws IOException{ Random generator = new Random(); int temp; System.out.println(" Enter Integers :"); //prompt user