-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagicDate.java
More file actions
64 lines (60 loc) · 1.76 KB
/
magicDate.java
File metadata and controls
64 lines (60 loc) · 1.76 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
public class magicDate{
public static void main(String[] args){
int month = 0;
int day = 0;
String year = "";
Scanner input = new Scanner(System.in);
while (true){
try{
System.out.println("Please enter a month in numeric form");
month = input.nextInt();
System.out.println("Please enter a day in numeric form");
day = input.nextInt();
System.out.println("Please enter a two-digit year");
if (input.hasNextInt()){
year = input.next();
}
else{
throw new java.util.InputMismatchException();
}
break;
}
catch(Exception e){
System.err.println(e);
System.out.println("\nOne of your inputs was not valid.");
input.next();
}
}
input.close();
System.out.println("\nYour month is: " + month + "\nYour day is: " + day + "\nYour year is: " + year);
System.out.println("Your date is: " + month + "/" + day + "/" + year);
if (month * day == Integer.parseInt(year)){
System.out.println("Your date is magic.");
}
else{
System.out.println("Your date is not magic.");
}
}
}
/*
* Welcome to DrJava. Working directory is F:\Current\Computer Science
> run magicDate
Please enter a month in numeric form
[DrJava Input Box]
Please enter a day in numeric form
[DrJava Input Box]
java.util.InputMismatchException
One of your inputs was not valid.
Please enter a month in numeric form
[DrJava Input Box]
Please enter a day in numeric form
[DrJava Input Box]
Please enter a two-digit year
[DrJava Input Box]
Your month is: 8
Your day is: 2
Your year is: 16
Your date is: 8/2/16
Your date is magic.
> */