Go Back   Computer Juice > Computer Software > Web Design, Hosting & SEO
Register Points Site Spy New Posts Donate Unanswered Posts Search Forum Rules


Reply
 
LinkBack Thread Tools
  #1  
Old 18th Mar 2007, 01:28 PM
No Avatar
T K  disclosed
New Member Group
 
T K is offline
 
Join Date: 18th Mar 2007
Last Online: 18th Mar 2007 01:28 PM
Posts: 1
iTrader: (0)
T K is on a distinguished road
Default Java - Putting generated random numbers into

an array? I have manged to create a program which generates 3 random numbers (luckyNum), then another 3 random numbers (playNum1, 2 and 3).How do I put this into an array so I can sort them into numerical order and see how many of the luckyNum's match the playNum's????? public void jButton1_actionPerformed(ActionEvent e) { luckyNum = 1 + (int)(Math.random()*49); jTextField1.setText(luckyNum+""); luckyNum = 1 + (int)(Math.random()*49); jTextField2.setText(luckyNum+""); luckyNum = 1 + (int)(Math.random()*49); jTextField3.setText(luckyNum+""); } public void jButtonPlay_actionPerformed(ActionEvent e) { playNum1 = 1+(int)(Math.random()*49); playNum2 = 1+(int)(Math.random()*49); playNum3 = 1+(int)(Math.random()*49); luckyNum = new Integer(jTextField1.getText()).intValue(); jTextFieldL1.setText(playNum1+""); jTextFieldL2.setText(playNum2+""); jTextFieldL3.setText(playNum3+"");
Digg this postDel.icio.us this postReddit this post Stumble this postFacebook this post
Reply With Quote
  #2  
Old 18th Mar 2007, 03:00 PM
No Avatar
titchyc  disclosed
New Member Group
 
titchyc is offline
 
Join Date: 18th Mar 2007
Last Online: 18th Mar 2007 03:00 PM
Posts: 1
iTrader: (0)
titchyc is on a distinguished road
Default Java - Putting generated random numbers into

best place to go is W3C
Digg this postDel.icio.us this postReddit this post Stumble this postFacebook this post
Reply With Quote
  #3  
Old 11th Jun 2007, 05:54 PM
No Avatar
JavaMan  United States
New Member Group
 
JavaMan is offline
 
Join Date: 11th Jun 2007
Last Online: 11th Jun 2007 06:46 PM
Posts: 9
iTrader: (0)
JavaMan is on a distinguished road
Default Java - Putting generated random numbers into

ok, this is a bit odd =)
// 3 random numers in an array
double num1 = 1+ Math.round(Math.random()*49);
double num2 = 1+ Math.round(Math.random()*49);
double num3 = 1+ Math.round(Math.random()*49);
double [] luckyNum = new double{num1, num2, num3};
// not sure what the JTextFields are doing there, but....
// to check if they are the same
if(luckyNum[0] == playNum1)
{
System.out.println("They Match!");
}

and goodnight
Digg this postDel.icio.us this postReddit this post Stumble this postFacebook this post
Reply With Quote
  #4  
Old 14th Jun 2007, 10:59 AM
No Avatar
Member Group
 
mr_miller is offline
 
Join Date: 4th May 2007
Last Online: 10th Jan 2008 10:58 AM
Posts: 99
iTrader: (0)
mr_miller is on a distinguished road
Default Java - Putting generated random numbers into

haven't done java commercially for a while but try this....

// Create a list with an ordered list of items
List sortedList = new LinkedList();
sortedList.addAll(Arrays.asList(new double[]{5,1, 13}));

// Search for the random number
int index = Collections.binarySearch(sortedList, 13);

Sorry haven't checked it, done from memory.

Last edited by mr_miller : 14th Jun 2007 at 10:59 AM.
Digg this postDel.icio.us this postReddit this post Stumble this postFacebook this post
Reply With Quote

Please support this forum, donate towards our running costs.
Reply

Thread Tools
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
random jabber Cew27 Off Topic Discussion 29 29th Apr 2008 01:31 PM
Random reboot... Axegrinder Windows Operating Systems 5 14th Feb 2008 07:21 AM
Dial-up access numbers phil66 Networking, Modems & VoIP 3 11th Feb 2008 08:27 PM
Random Shutdowns tuxedoman7 General Hardware Chat 4 3rd Jan 2008 06:39 PM
Java programming question. What do java rhohltjr Web Design, Hosting & SEO 4 20th Mar 2007 05:09 AM


Copyright ©2006 - 2008 Computer Juice.

Powered by vBulletin® Copyright ©2000 - 2009 Jelsoft Enterprises Ltd. SEO by vBSEO ©2008, Crawlability, Inc.