| | |
Need help with Lottery program
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 6
Reputation:
Solved Threads: 0
Im new to java and just trying to figure out the basics. i cannot figure out what is wrong with my program. Any suggestions on whats wrong?
Java Syntax (Toggle Plain Text)
4import java.util.Scanner; 5 6public class Lottery 7{ 8 public static void main(String[] args) 9 { 10 //Generate random lottery numbers 11 int lottery = (int)(Math.random() * 1000); 12 System.out.printf("%d" , lottery); 13 14 //Create Scanner 15 Scanner input = new Scanner(System.in); 16 System.out.print("Enter your lottery pick (three digits): "); 17 int guess = input.nextInt(); 18 19 //Determine whether or not the entered guess is some kind of match 20 if(guess == lottery) 21 System.out.println("Exact mactch: you win $10,000"); 22 else if (guess % 100 == lottery / 100 && 23 guess / 100 == lottery % 100 && 24 guess % 10 == lottery / 10 && 25 guess / 10 == lottery % 10) 26 System.out.println("Match all digits: you win $3,000"); 27 else if (guess % 100 == lottery / 100 || 28 guess % 100 == lottery % 100 || 29 guess / 100 == lottery / 100 || 30 guess / 100 == lottery % 100 || 31 guess % 10 == lottery / 10 || 32 guess % 10 == lottery % 10 || 33 guess / 10 == lottery / 10 || 34 guess / 10 == lottery % 10 ) 35 System.out.println("Match one digit: you win $1,000"); 36 else 37 System.out.println("Sorry, no match"); 38 } 39}
Last edited by Andrewsc1; Feb 17th, 2009 at 6:03 pm.
•
•
Join Date: Feb 2009
Posts: 6
Reputation:
Solved Threads: 0
sorry. well the program is supposed to tell if you won the randomly generated lottery number. i used the scanner class so that the user could enter in a number. i extracted digits from the lottery class and guess class using the "%" and "/". i cannot figure out why i cannot get the "Match all digits: you win $3,000" to appear in the console. so in all reality im just looking into why lines 22-25 are not extracting the digits.
Last edited by Andrewsc1; Feb 17th, 2009 at 6:20 pm.
![]() |
Similar Threads
- Random Number Problem For Lottery Program (Visual Basic 4 / 5 / 6)
- Lottery Validation (Pascal and Delphi)
- Another Lottery Program sorting problem (Visual Basic 4 / 5 / 6)
- Lottery Program for VB (VB.NET)
- C++ Random Numbers (C++)
- lottery program help (Java)
- Lottery Program (Java)
Other Threads in the Java Forum
- Previous Thread: returning null
- Next Thread: RMI Client Server
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu update windows working






