forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketNumber.java
More file actions
32 lines (26 loc) · 873 Bytes
/
TicketNumber.java
File metadata and controls
32 lines (26 loc) · 873 Bytes
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
//Exercise 5-H.
import java.util.Scanner;
public class TicketNumber
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int ticketNumber;
System.out.print("What is the Ticket Number? ");
ticketNumber = in.nextInt();
System.out.println("This is the Ticket Number you entered: " + ticketNumber);
int ticketPrefix = ticketNumber / 10;
int lastDigit = ticketNumber % 10;
System.out.println("The Ticket Prefix is: " + ticketPrefix);
System.out.println("The last digit of the Ticket is: " + lastDigit);
boolean isValid = ((ticketPrefix % 7) == lastDigit);
if (isValid)
{
System.out.println("This is a good number.");
}
else
{
System.out.println("This is a bad number.");
}
}
}