Skip to content

Commit

Permalink
finished exercise 32
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-Birkey committed Mar 7, 2024
1 parent 1ea55ac commit c214fc3
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/com/github/jonathanbirkey/chapter05/Exercise32.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,44 @@
* @author : Jonathan Birkey
* @mailto : [email protected]
* @created : 28Feb2024
* <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
* 101 to 2100, separated by exactly one space. Also display the number of leap years in this
* period.
* <p>(Game: lottery) Revise Listing 3.8, Lottery.java, to generate a lottery of a two-digit
* number. The two digits in the number are distinct. (Hint: Generate the first digit. Use a
* loop to continuously generate the second digit until it is different from the first digit.)
*/
package com.github.jonathanbirkey.chapter05;

import java.util.Scanner;

public class Exercise32 {
public static void main(String[] args) {
// TODO: solve
int lotteryDigit1 = (int) (Math.random() * 10);
int lotteryDigit2 = 0;
do {
lotteryDigit2 = (int) (Math.random() * 10);
}while(lotteryDigit1 == lotteryDigit2);


Scanner input = new Scanner(System.in);
System.out.print("Enter your lotter pick (two digits): ");
int guess = input.nextInt();
input.close();

int guessDigit1 = guess / 10;
int guessDigit2 = guess % 10;

System.out.printf("The lottery number is %d%d\n", lotteryDigit1, lotteryDigit2);

if (guessDigit1 == lotteryDigit1 && guessDigit2 == lotteryDigit2) {
System.out.println("Exact match: you win $10,000");
} else if (guessDigit2 == lotteryDigit1 && guessDigit1 == lotteryDigit2) {
System.out.println("Match all digits: you win $3,000");
} else if (guessDigit1 == lotteryDigit1
|| guessDigit1 == lotteryDigit2
|| guessDigit2 == lotteryDigit1
|| guessDigit2 == lotteryDigit2) {
System.out.println("Match one digit: you win $1,000");
} else {
System.out.println("Sorry, no match");
}
}
}

0 comments on commit c214fc3

Please sign in to comment.