java 输入年月日计算出是那一年的第几天
- 提问者网友:温柔港
- 2021-04-28 14:50
- 五星知识达人网友:醉吻情书
- 2021-04-28 15:55
//对输入的年,月、日,给出这天是这年的第几天
import java.io.*;
public class days{
public static void main(String[] args) throws IOException{
BufferedReader Reader=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please input the year: ");
int year=Integer.parseInt(Reader.readLine());
System.out.println("Please input the month: ");
int month=Integer.parseInt(Reader.readLine());
System.out.println("Please input the day: ");
int day=Integer.parseInt(Reader.readLine());
int daynum=0,daysum=0;
for(int i=1;i<month;i++)
{
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
daynum=31;break;
case 4:
case 6:
case 9:
case 11:
daynum=30;break;
case 2:
if(year%4==0&&year%100!=0||year%400==0)
daynum=29;
else
daynum=28;
break;
}
daysum+=daynum;
}
daysum+=day;
System.out.print("这天是这年的第"+daysum+"天");
}
}
- 1楼网友:过活
- 2021-04-28 18:33
貌似有那么一个函数吧, M表示年中的月份,D表示年中的天数,d表示月中的天数,你试试转换一下。
•SimpleDateFormat s2 = new SimpleDateFormat("yyyy年MM月D");
- 2楼网友:忘川信使
- 2021-04-28 17:12