File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Trouble with lottery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with lottery" Watch "Trouble with lottery" New topic

Trouble with lottery

Cutter Jones

Joined: Sep 05, 2009
Posts: 2
Good Morning
Im a very new Java enthusiast,

I'm try to find some help with this please

User inputs 3 numbers
for correct matches then
1 correct wins $10.00
2 correct wins $100.00
3 correct wins $1000.00

if user inputs 123
and random generator comes back 111 he/she should only win once

if user inputs 120 should win twice...etc...etc...

I have if all three numbers match, but seem to have trouble with the other parts...

What I have so far

import java.util.*;
import javax.swing.JOptionPane;

public class Lottery

public static void main (String[] args)

int allRanNumbers;

allRanNumbers = (int)(Math.random() * 1000);

String guessString;
int guess;

guessString = JOptionPane.showInputDialog(null,
"Please enter 3 digits from 0-9", "Lottery Numbers",
guess = Integer.parseInt(guessString);

if (guess == allRanNumbers)

System.out.println("You matched two: you win $1000.00");


any help would be greatly appreciated

Thank you

Henry Wong

Joined: Sep 28, 2004
Posts: 20530

any help would be greatly appreciated

It would help if you tell us what problem you are running into. And what are you confused with.

Telling us the assignment, and the code that you did so far, isn't enough for us to give you a hint in the right direction.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Cutter Jones

Joined: Sep 05, 2009
Posts: 2
The assignment is create a lottery
where the user inputs 3 numbers and wins $$ based on the amount of numbers he or she matches.

the user cannot win with matching two numbers
example if 123 is the number randomly generated and the user inputs 121, he /she cannot win twice with the numer 1
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46367
Welcome to JavaRanch
How do you think you can check whether you have the "1" matching twice? Or can you stop checking when you have found the first "1"?
Cutter Jones

Joined: Sep 05, 2009
Posts: 2
Thanks Campbell Richie...

I tries using three seperate "random" instances but couldn't make heads or tails of my if statements, and scraped the idea.

Do you think that is the way to go?
I agree. Here's the link:
subject: Trouble with lottery
It's not a secret anymore!