根据输入的日期,计算是这一年的第几天。。
详细描述:
输入某年某月某日,判断这一天是这一年的第几天?。
测试用例有多组,注意循环输入
接口设计及说明:
/***************************************************************************** Description : 数据转换 Input Param : year 输入年份 Month 输入月份 Day 输入天 Output Param : Return Value : 成功返回0,失败返回-1(如:数据错误) *****************************************************************************/ public static int iConverDateToDay(int year, int month, int day) { /* 在这里实现功能,将结果填入输入数组中*/ return 0; } /***************************************************************************** Description : Input Param : Output Param : Return Value : 成功:返回outDay输出计算后的第几天; 失败:返回-1 *****************************************************************************/ public static int getOutDay() { return 0; }
输入多行,每行空格分割,分别是年,月,日
成功:返回outDay输出计算后的第几天; 失败:返回-1
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = br.readLine()) != null) { String str[] = s.split(" "); int y = Integer.parseInt(str[0]);//年份 int m = Integer.parseInt(str[1]);//月份 int d = Integer.parseInt(str[2]);//日期 int a[] = new int[12]; a[0] = 31; a[2] = 31; a[3] = 30; a[4] = 31; a[5] = 30; a[6] = 31; a[7] = 31; a[8] = 30; a[9] = 31; a[10] = 30; a[11] = 31; //判断是不是闰年 if (y % 4 == 0 && y % 100 != 0) a[1] = 29; else a[1] = 28; System.out.println(theday(a,m-1,d)); } } private static int theday(int a[], int m, int d) { // TODO Auto-generated method stub int temp = 0; for(int i = 0;i<m;i++) { temp +=a[i]; } return temp+d; } }
