-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHappyBirthDay.java
More file actions
43 lines (35 loc) · 1.06 KB
/
Copy pathHappyBirthDay.java
File metadata and controls
43 lines (35 loc) · 1.06 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
package chp4;
import java.util.Scanner;
public class HappyBirthDay {
final static int CURRENTMONTH = 10;
final static int CURRENTDAY = 3;
final static int CURRENTYEAR = 2008;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println(daysTillNextBDay(9, 10));
}
public static int daysTillNextBDay(int month, int day)
{
boolean nextYear = false;
if(month<CURRENTMONTH){nextYear=true;}
else if(month==CURRENTMONTH && day<CURRENTDAY){nextYear=true;}
else if(month==CURRENTMONTH && day==CURRENTDAY){System.out.println("Happy Birthday");}
if(nextYear==false)
{
return absoluteDay(month, day)-absoluteDay(CURRENTMONTH, CURRENTDAY);
}
return 365-(absoluteDay(CURRENTMONTH, CURRENTDAY)-absoluteDay(month, day));
}
public static int absoluteDay(int month, int day)
{
int[] daysInMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int result = 0;
for(int i = 0; i<month-1; i++)
{
result+=daysInMonth[i];
}
result+=day;
return result;
}
}