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?

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}

Recommended Answers

All 4 Replies

You should probably explain what it is doing wrong, what you expect it to do, and any errors you receive, rather than expecting people here to pick through it and play "find the problem with this".

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.

Most likely because the formula you implemented to determine "match all digits" doesn't do that at all. Those are rather odd relationships that you are expecting between the division and mod results. You need to break the numbers into their components before you make the comparison checks.

thank you for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.