-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay7.java
More file actions
59 lines (41 loc) · 1.19 KB
/
Day7.java
File metadata and controls
59 lines (41 loc) · 1.19 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
/*
Day 7 coding Statement: Write a program to find Number of days in a given month of a given year
Description
Get the number of month and year as input from the user and check the number of days present in that month.
Input
Enter month : 2
Enter year : 2000
Output
29
*/
import java.util.*;
public class Day7
{
public static boolean isLeapYear(int year){
if(year%400==0){
return true;
}
if(year%100==0){
return false;
}
if(year%4==0){
return true;
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter year and month :");
int year=sc.nextInt();
int month=sc.nextInt();
if(isLeapYear(year) && month==2){
System.out.println("The number of days are "+29);
}else if(month==2){
System.out.println("The number of days are "+28);
}else if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
System.out.println("The number of days are "+31);
}else{
System.out.println("The number of days are "+30);
}
}
}