![]() |
| |||||||
| |


|
| | LinkBack | Thread Tools |
|
#1
| ||||
| ||||
| 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+""); |
| |
|
#2
| ||||
| ||||
| best place to go is W3C |
|
#3
| ||||
| ||||
| 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 |
|
#4
| ||||
| ||||
| 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. |
| Please support this forum, donate towards our running costs. |
![]() |
| Thread Tools | |
|
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 |
| Powered by vBulletin® Copyright ©2000 - 2009 Jelsoft Enterprises Ltd. SEO by vBSEO ©2008, Crawlability, Inc. |