This discussion is archived
13 Replies Latest reply: Sep 14, 2010 6:52 PM by EJP

# Generating Random numbers

Currently Being Moderated
how do I generates 6 pairs of random integer (int) values with values between 1 and 100. For each generated pair, i want to use an if-else statement to classify the first value as greater than, less than, or equal to the second value. my output will display BOTH generated values as well as the classification in the format "Number 1 <classification> Number 2", one number pair per output line, where <classification> is "less than", "equals" or "greater than".
• ###### 1. Re: Generating Random numbers
Currently Being Moderated
Thank you for simply re-wording your homework assignment and attempting to dump it on us.
Would you like fries with that?
• ###### 2. Re: Generating Random numbers
Currently Being Moderated
how do I generates 6 pairs of random integer (int) values with values between 1 and 100. For each generated pair, i want to use an if-else statement to classify the first value as greater than, less than, or equal to the second value. my output will display BOTH generated values as well as the classification in the format "Number 1 <classification> Number 2", one number pair per output line, where <classification> is "less than", "equals" or "greater than".
Okay, so exactly what have you tried and exactly what problems did you encounter?
• ###### 3. Re: Generating Random numbers
Currently Being Moderated
jverd wrote:
how do I generates 6 pairs of random integer (int) values with values between 1 and 100. For each generated pair, i want to use an if-else statement to classify the first value as greater than, less than, or equal to the second value. my output will display BOTH generated values as well as the classification in the format "Number 1 <classification> Number 2", one number pair per output line, where <classification> is "less than", "equals" or "greater than".
Okay, so exactly what have you tried and exactly what problems did you encounter?
Ooh! Ooh! I know!
He tried: Dumping his homework on a forum (or more than one, probably)
The problems he encountered: Received flak for doing so
• ###### 4. This Thread is now moved
Currently Being Moderated
Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
• ###### 5. Re: Generating Random numbers
Currently Being Moderated
If you decide to actually start doing your own homework, you may notice that each sentence of your assignment maps almost directly to equivalent Java code in the solution. Give it a shot.
• ###### 6. Re: Generating Random numbers
Currently Being Moderated
Wow. If you want to try and recover from the beating you took here, you better produce some code and show us what you have so far. You can't come in here ask someone to generate code for you. Effort goes a long ways in here.
• ###### 7. Re: Generating Random numbers
Currently Being Moderated
I'd like to know how to generate some random women myself... and I hope my wife and kids aint reading this.
• ###### 8. Re: Generating Random numbers
Currently Being Moderated
Hi Guys,

I have read all your mails, messages and abuses. I think this forum is to help and solve people's problems.

By the way, I have come up with a solution but I still want you guys to give it a second look to see if it is achieving the purpose of the post.

import java.util.*;

public class RandomIntegerCompare {

public static void main(String[] args) {

for(int i = 1; i <= 6; i++){
Random rand = new Random();
int NumOne = rand.nextInt(100);

int NumTwo = rand.nextInt(100);

System.out.println("NumOne = " + NumOne + " NumTwo = " + NumTwo);
if (NumOne < NumTwo)
System.out.println( "NumOne < NumTwo");
else if (NumOne > NumTwo)
System.out.println("NumOne > NumTwo");
else
System.out.println("NumOne=NumTwo");

}
}

}

Result

NumOne = 81 NumTwo = 91
NumOne < NumTwo
NumOne = 54 NumTwo = 36
NumOne > NumTwo
NumOne = 5 NumTwo = 0
NumOne > NumTwo
NumOne = 37 NumTwo = 52
NumOne < NumTwo
NumOne = 36 NumTwo = 90
NumOne < NumTwo
NumOne = 34 NumTwo = 0
NumOne > NumTwo
• ###### 9. Re: Generating Random numbers
Currently Being Moderated
Hi Guys,

DId you also read the good advice on how to get help?
I think this forum is to help and solve people's problems.
Help, yes. Do your work for you, no. Go back and re-read your first post. Does it look like you're making a reasonable request for help, including providing people with enough information to understand what specifically you're having trouble with? Or does it look like, "I can't be bothered to make an effort, not even to explain to you what I've tried and where specifically I'm stuck"?
• ###### 10. Re: Generating Random numbers
Currently Being Moderated
By the way, I have come up with a solution but I still want you guys to give it a second look to see if it is achieving the purpose of the post.
If you want anyone to read your code, you'll need to present it formatted, in code tags. Copy/paste from your original source in your editor (NOT from your previous post here). Highlight the code, and click the CODE button. Use the Preview tab to see how your post will look.

However, you don't really need anyone here to tell you whether it meets your requirements or not. You know what the code is supposed to do. Run it with appropriate test data and see if it produces the expected results.
• ###### 11. Re: Generating Random numbers
Currently Being Moderated
If you want anyone to read your code, you'll need to present it formatted, in code tags. Copy/paste from your original source in your editor (NOT from your previous post here). Highlight the code, and click the CODE button. Use the Preview tab to see how your post will look

Thank you for your advice, I am new this forum and Java.
• ###### 12. Re: Generating Random numbers
Currently Being Moderated
Hi Guys,