forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTravelTickets.java
More file actions
30 lines (28 loc) · 984 Bytes
/
TravelTickets.java
File metadata and controls
30 lines (28 loc) · 984 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
import java.util.Scanner;
public class TravelTickets
{
public static void main(String[] args)
{
System.out.println("++++++++++++++++++++++++++++++++++++++++");
System.out.println("++Travel Ticket Validation Application++");
System.out.println("++++++++++++++++++++++++++++++++++++++++\n");
Scanner scanner = new Scanner(System.in);
int ticketNumber;
System.out.print("Please enter a value: ");
ticketNumber = scanner.nextInt();
int lastDigit = ticketNumber % 10;
int ticketPrefix = ticketNumber / 10;
boolean result = (lastDigit == (ticketPrefix % 7));
if (result)
{
System.out.println("\nGood Number");
}
else
{
System.out.println("\nBad Number");
}
//System.out.println(15412 % 7);
System.out.println("last digit: " + lastDigit);
System.out.println("ticket prefix: " + ticketPrefix % 7);
}
}