Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Reply
Old 11-01-2009, 12:29 PM   #1 (permalink)
 
Monster Techie

Join Date: Mar 2008

Location: Logan, WV

Posts: 1,765

wafflehammer is on a distinguished road

Send a message via AIM to wafflehammer
Default Java help

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 :\
__________________

Core i7 920 @ 3.0Ghz
GIGABYTE GA-EX58-UD5
6gb G.Skill 1600mhz/9-9-9-24
Corsair 750XT
EVGA GTX 260---216core
WD 640gb
14590 3dmarks @ stock
wafflehammer is online now   Reply With Quote
Old 11-01-2009, 01:00 PM   #2 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default Re: Java help

Is this one of the pages you already checked out ?

Java Practices -> Generate random numbers
__________________
  • Operating system(s) : Windows 7 Home Premium x64 | Ubuntu 9.10
  • CPU : Pentium Dual-Core E5200 @ 2.50GHz /Socket 775 LGA
  • Memory: 2X 2GB DDR2 SDRAM
  • Hard drive: 640 GB Western Digital Caviar Blue 7200rpm WD6400AAKS-75
  • Motherboard : Dell 0U880P
  • Video: nVidia GeGorce 8400GS
  • Chipset : Intel G41

<<<<< If you found anything I said helpful, please click the or under my avatar
oldskool is offline   Reply With Quote
Old 11-01-2009, 01:03 PM   #3 (permalink)
 
Monster Techie

Join Date: Mar 2008

Location: Logan, WV

Posts: 1,765

wafflehammer is on a distinguished road

Send a message via AIM to wafflehammer
Default Re: Java help

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
__________________

Core i7 920 @ 3.0Ghz
GIGABYTE GA-EX58-UD5
6gb G.Skill 1600mhz/9-9-9-24
Corsair 750XT
EVGA GTX 260---216core
WD 640gb
14590 3dmarks @ stock
wafflehammer is online now   Reply With Quote
Old 11-01-2009, 01:07 PM   #4 (permalink)
oldskool's Avatar
 
Electrical Systems Design

Join Date: Jun 2008

Location: Maine, USA

Posts: 1,646

oldskool has a spectacular aura aboutoldskool has a spectacular aura about

Default Re: Java help

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.
__________________
  • Operating system(s) : Windows 7 Home Premium x64 | Ubuntu 9.10
  • CPU : Pentium Dual-Core E5200 @ 2.50GHz /Socket 775 LGA
  • Memory: 2X 2GB DDR2 SDRAM
  • Hard drive: 640 GB Western Digital Caviar Blue 7200rpm WD6400AAKS-75
  • Motherboard : Dell 0U880P
  • Video: nVidia GeGorce 8400GS
  • Chipset : Intel G41

<<<<< If you found anything I said helpful, please click the or under my avatar
oldskool is offline   Reply With Quote
Old 11-01-2009, 01:12 PM   #5 (permalink)
 
Monster Techie

Join Date: Mar 2008

Location: Logan, WV

Posts: 1,765

wafflehammer is on a distinguished road

Send a message via AIM to wafflehammer
Default Re: Java help

eh well it's not due till wednesday so i'll just ask tomorrow in class lol got a view other things i need to know too
__________________

Core i7 920 @ 3.0Ghz
GIGABYTE GA-EX58-UD5
6gb G.Skill 1600mhz/9-9-9-24
Corsair 750XT
EVGA GTX 260---216core
WD 640gb
14590 3dmarks @ stock
wafflehammer is online now   Reply With Quote
Old 11-01-2009, 02:43 PM   #6 (permalink)
 
Newb Techie

Join Date: Oct 2009

Posts: 9

reedjasonf is on a distinguished road

Default Re: Java help

Isn't there just a math.rand(2,12) ?
reedjasonf is offline   Reply With Quote
Old 11-01-2009, 05:00 PM   #7 (permalink)
 
Monster Techie

Join Date: Mar 2008

Location: Logan, WV

Posts: 1,765

wafflehammer is on a distinguished road

Send a message via AIM to wafflehammer
Default Re: Java help

Quote:
Originally Posted by reedjasonf View Post
Isn't there just a math.rand(2,12) ?
yea that's what i thought...and I think i remember them saying something about that. But on the other hand they told us not to do it one way and that might be the way :\
__________________

Core i7 920 @ 3.0Ghz
GIGABYTE GA-EX58-UD5
6gb G.Skill 1600mhz/9-9-9-24
Corsair 750XT
EVGA GTX 260---216core
WD 640gb
14590 3dmarks @ stock
wafflehammer is online now   Reply With Quote
Old 11-01-2009, 08:39 PM   #8 (permalink)
SapperX's Avatar
 
Putting the X in Sapper

Join Date: Jul 2007

Location: USA

Posts: 706

SapperX is on a distinguished road

Default Re: Java help

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;
__________________
My Current PC-
eVGA 680i | Intel Q6600 G0 |Western Digital 250gb HD
Seagate 500gb HD | Western Digital 500gb HD | VisionTek HD4870 | 4gb Cruical Ballistix Tracer DDR2 800
600w Coolmax Silent Fan PSU | Cooler Master Centurian 590 | Samsung 24" LCD | Dell 22" LCD

-900HA EEE pc
SapperX is offline   Reply With Quote
Old 11-02-2009, 06:45 PM   #9 (permalink)
 
Monster Techie

Join Date: Mar 2008

Location: Logan, WV

Posts: 1,765

wafflehammer is on a distinguished road

Send a message via AIM to wafflehammer
Default Re: Java help

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);
__________________

Core i7 920 @ 3.0Ghz
GIGABYTE GA-EX58-UD5
6gb G.Skill 1600mhz/9-9-9-24
Corsair 750XT
EVGA GTX 260---216core
WD 640gb
14590 3dmarks @ stock
wafflehammer is online now   Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Error 25099 Unzipping Core Files Failed Osiris Tips, Tricks & Tutorials 0 06-30-2009 09:24 AM
Java Problem s1nglef1sh Windows Operating Systems and Software 5 10-06-2008 05:10 PM
Need Java help CrazeD Programming Discussions 4 09-29-2008 06:29 PM
Updates for Java eliminate many security holes Trotter Browser & General Internet Questions 1 07-11-2008 09:54 PM