forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotteryUsingStrings.java
More file actions
executable file
·47 lines (45 loc) · 1.64 KB
/
LotteryUsingStrings.java
File metadata and controls
executable file
·47 lines (45 loc) · 1.64 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
45
46
47
/* */ package ch04;
/* */
/* */ import java.util.Scanner;
/* */
/* */
/* */ public class LotteryUsingStrings
/* */ {
/* */ public static void main(String[] args) {
/* 9 */ String lottery = "" + (int)(Math.random() * 10.0D) + (int)(Math.random() * 10.0D);
/* */
/* */
/* 12 */ Scanner input = new Scanner(System.in);
/* 13 */ System.out.print("Enter your lottery pick (two digits): ");
/* 14 */ String guess = input.nextLine();
/* */
/* */
/* 17 */ int lotteryDigit1 = lottery.charAt(0);
/* 18 */ int lotteryDigit2 = lottery.charAt(1);
/* */
/* */
/* 21 */ int guessDigit1 = guess.charAt(0);
/* 22 */ int guessDigit2 = guess.charAt(1);
/* */
/* 24 */ System.out.println("The lottery number is " + lottery);
/* */
/* */
/* 27 */ if (guess.equals(lottery)) {
/* 28 */ System.out.println("Exact match: you win $10,000");
/* 29 */ } else if (guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) {
/* */
/* 31 */ System.out.println("Match all digits: you win $3,000");
/* 32 */ } else if (guessDigit1 == lotteryDigit1 || guessDigit1 == lotteryDigit2 || guessDigit2 == lotteryDigit1 || guessDigit2 == lotteryDigit2) {
/* */
/* */
/* */
/* 36 */ System.out.println("Match one digit: you win $1,000");
/* */ } else {
/* 38 */ System.out.println("Sorry, no match");
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch04/LotteryUsingStrings.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/