# Trouble with detecting digits

• October 7th, 2013, 11:15 PM
thegorila78
Trouble with detecting digits
Here is the question assigned to me in class...

Suppose you want to develop a program to play lottery. The program randomly
generates a lottery of a two-digit number, prompts the user to enter a two-digit number,
and determines whether the user wins according to the following rule:
a. If the user input matches the lottery in exact order, the award is \$10,000. 2/2

b. If all the digits in the user input match all the digits in the lottery, the award is
\$3,000.
c. If one digit in the user input matches a digit in the lottery, the award is \$800.

Note that, in the program, make sure that the lottery number generated must be two
digits.
__________________________________________________ _______________________
So far I have created the random generator and scanner to get the user input. The problem I am having though is for example if i get a number 1-9, how can i make that into 2 digits for example 09 or 07 etc. I'm sure I have to use decimalformat but that doesnt seem to work. Also, I am having a problem detecting each individual digit. I know I have to use the number%10 but then how do i get the first digit. Any help would be greatly appreciated.
• October 7th, 2013, 11:23 PM
Junky
Re: Trouble with detecting digits
This might be easier if you deal with the numbers as Strings and chars instead of ints. For single digit numbers simply concat a '0' to the front.
• October 7th, 2013, 11:40 PM
thegorila78
Re: Trouble with detecting digits
I imported the java.util.Random and then I created a random object called myGenerator. When I try to declare my random number as a String I get an error:
Error: cannot find symbol
symbol: method nextLine(int)
location: variable myGenerator of type java.util.Random
my code looks like this:
String lottery = myGenerator.nextLine(99) + 1;

What am I doing wrong?
• October 7th, 2013, 11:51 PM
Junky
Re: Trouble with detecting digits
As the error message says: the Random class does not have a nextLine method. You can only call methods that exist not ones you think exist. Even if it was to work the Random class generates numbers. You would have to convert it to a String before assigning it to a String variable. String class and the Integer class both have a method to do this.