菜鸟涂鸦作品展_No.14

//【程序14】 题目:输入某年某月某日,判断这一天是这一年的第几天?
import java.io.*;
public class _14_tianshu {
int runnian(int nian,int yue,int ri){
int month[]={31,29,31,30,31,30,31,31,30,31,30,31};
int tianshu=0;
for (int i=0 ; i<yue-1 ; i++){
tianshu=tianshu+month[i];
}
tianshu=tianshu+ri;
System.out.println(nian+"年"+yue+"月"+ri+"日是第"+tianshu+"天");
return 0;
}
int punian(int nian,int yue,int ri){
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
int tianshu=0;
for (int i=0 ; i<yue-1 ; i++){
tianshu=tianshu+month[i];
}
tianshu=tianshu+ri;
System.out.println(nian+"年"+yue+"月"+ri+"日是第"+tianshu+"天");
return 0;
}
public static void main(String[] args)throws Exception{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
_14_tianshu ts=new _14_tianshu();
System.out.println("请输入要查询的日期");
int nian=Integer.parseInt(br.readLine());
int yue=Integer.parseInt(br.readLine());
int ri=Integer.parseInt(br.readLine());
int flag=0;
if (nian%4==0 && nian%100!=0)
flag=1;
if (flag==0)
ts.punian(nian,yue,ri);
else if (flag==1)
ts.runnian(nian,yue,ri);
}
}

 

涂鸦心得:

  例子里面又用了动态数组,今天还有别的任务,改天再学习一下例子上的方法。。。

你可能感兴趣的:(作品)