JAVA课程设计天数计算器(输入年月日等到是当年的第几天)Would文档
发布网友
发布时间:2022-04-30 22:45
我来回答
共1个回答
热心网友
时间:2023-10-05 13:26
// 你试试这个能不能实现
import java.io.*;
public class DateCal {
static public void main(String[] args) {
int year, month, day;
int days = 0;
boolean luinian = false;
System.out.print("input the year:");
year = IO.getInt();
System.out.print("input the month:");
month = IO.getInt();
System.out.print("input the day:");
day = IO.getInt();
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
luinian = true;
}
for (int i = 1; i < month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days += 31;
break;
case 2:
days += 28;
break;
case 4:
case 6:
case 9:
case 11:
days += 30;
break;
}
}
if (luinian && month > 2) {
days++;
}
days += day;
System.out.println(year + "年" + month + "月" + day + "日是" + year + "的第"
+ days + "天");
}
}
class IO {
public static int getInt() {
DataInputStream dis = new DataInputStream(System.in);
int value = 0;
try {
@SuppressWarnings("deprecation")
String str = dis.readLine();
value = Integer.parseInt(str);
} catch (IOException e) {
e.printStackTrace();
}
return value;
}
}