Java help

Status
Not open for further replies.

wafflehammer

Fully Optimized
Messages
2,502
Location
Logan, WV
Okay I'm working on a lab for my computer science class and part of it has my stuck :| We're writing a program to do multiplication tables and we have to have it randomly generate a number between 2-12..and I totally can't remember how to do it :| I tried looking on google but every example has a bunch of stuff in it that I've never seen so there is no use for me to even try doing it that way :\
 
yes :| first thing i notice is the

public static final void thing :|

all i know is

public static void main

so i can tell that's too advance for me already :(
 
Yeah, the first one refers to other forms, and the latter, familiar one is the current form. That is as far as I know too in respect to that part of Java. I have just downloaded NetBeans so I can get back into Java programming that I started a while back. So we can maybe compare notes. :)
 
Initialize with this statement:

Random generator = new Random();

Then assign a new int a random number with "generator".

int yourNum = generator.nextInt(11) + 2;

The (11) means it will generate a number between 0 and 10... then offset it to 2 to 12 using +2.

Thats it! Your random number is now in the variable "yourNum".


Random generator = new Random();
int yourNum = generator.nextInt(11) + 2;
 
thanks sapper..that's exactly what my book says ( no clue why i didn't look there first lol )

this is what it gives:

Random generator = new Random();
int d = 1 + generator.nextInt(6);
 
Status
Not open for further replies.
Back
Top Bottom