-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotteryUsingString.java
More file actions
44 lines (37 loc) · 1.11 KB
/
LotteryUsingString.java
File metadata and controls
44 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
public class LotteryUsingString
{
public static void main(String[] args)
{
String lottery = "" + (int)(Math.random()*10)+(int)(Math.random() * 10);
Scanner input = new Scanner(System.in);
System.out.println("Enter your lottery pick(two digits):");
String guess = input.nextLine();
// Get digits from lottery
int lotteryDigit1 = lottery.charAt(0);
int lotteryDigit2 = lottery.charAt(1);
// Get digits from guess
int guessDigit1 = guess.charAt(0);
int guessDigit2 = guess.charAt(1);
System.out.println("The lottery number is " + lottery);
if (guess.equals(lottery))
{
System.out.println("Exact match: you win 10,000 RS");
}
else if( guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit1)
{
System.out.println("Match all digits: you win 3,000 RS");
}
else if(guessDigit1 == lotteryDigit1
|| guessDigit1 == lotteryDigit2
|| guessDigit2 == lotteryDigit1
|| guessDigit2 == lotteryDigit2 )
{
System.out.println("Match one digit: you win 1,000 RS");
}
else
{
System.out.println("Sorry, no match");
}
}
}