Update
This commit is contained in:
1 parent
eec518632e
commit
7275bdb0e8
240 files changed
+22
-1
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package finalexam.StandardIO;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class DateCalculation {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String s = sc.nextLine();
|
||||
String[] arr = s.split("[-]");
|
||||
int year = Integer.parseInt(arr[0]);
|
||||
int month = Integer.parseInt(arr[1]);
|
||||
int day = Integer.parseInt(arr[2]);
|
||||
int days[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
if (isLeapYear(year))
|
||||
days[2] = 28;
|
||||
int ans = day;
|
||||
for (int i = 1; i < month; i++) {
|
||||
ans += days[i];
|
||||
}
|
||||
System.out.println(ans);
|
||||
}
|
||||
|
||||
public static boolean isLeapYear(int year) {
|
||||
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user