ちょっぴりムズムズしたので。
class sec { public static void main(String args[]){ int year = 2009; int month = 6; int day = 4; //日付を入力してください。 int yday[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; long days = 0; days += (year - 1) * 365 + leapdays(year - 1); days += yday[month - 1] + (((month > 2) && leapyear(year)) ? 1 : 0); days += day - 1; long sec = days * 86400; System.out.println(year + "年" + month + "月" + day + "日0時0分0秒までの秒数は、" + sec + "秒です"); } public static int leapdays(int year) { return (year / 4) - (year / 100) + (year / 400); } public static boolean leapyear(int year) { return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); } }
こんな感じ?
Cだとこんな感じか。 #include <stdio.h>int isLeap(int year) { return ((year%400 == 0) || (year%4 == 0) &amp;&amp; (year%100 != 0)) ? 1 : 0;}int todays(int year, int month, int day) { int MonthDays[] = {31, 28, 31, 30, 31, 30, ...