import java.util.Scanner;
/**
*@author 作者 Your-Name:
*@version 创建时间:
*类说明:输入年月日,输出周几
*/
public class ChenQian39 {
public static int getDay(int year,int month,int day)
{
int num = 0;
int i;
for(i = 2000;i <= year;i ++)
{
if(i == year)
{
switch(month - 1)
{
case 11:
num += 30;
case 10:
num += 31;
case 9:
num += 30;
case 8:
num += 31;
case 7:
num += 31;
case 6:
num += 30;
case 5:
num += 31;
case 4:
num += 30;
case 3:
num += 31;
case 2:
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
num += 29;
}
else
{
num += 28;
}
case 1:
num += 31;
}
num += day;
}
else
{
if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
{
num += 366;
}
else
{
num += 365;
}
}
}
return num;
}
public static void getWeek(int sum)
{
int a;
a = sum % 7;
System.out.print("今天的日期:");
switch(a)
{
case 0:
System.out.println("周五");
break;
case 1:
System.out.println("周六");
break;
case 2:
System.out.println("周日");
break;
case 3:
System.out.println("周一");
break;
case 4:
System.out.println("周二");
break;
case 5:
System.out.println("周三");
break;
case 6:
System.out.println("周四");
break;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int year;
int month;
int day;
int sum;
int choice;
Scanner input = new Scanner(System.in);
System.out.println("*******<<<<日期查询>>>>******");
System.out.println("******本系统只支持2000年后的日期******");
while(true)
{
System.out.println("*********************************");
System.out.println("1,查询日期");
System.out.println("2,退出系统");
System.out.print("请输入你的选择:");
choice = input.nextInt();
if(choice == 1)
{
System.out.print("请输入年份:");
year = input.nextInt();
System.out.print("请输入月份:");
month = input.nextInt();
System.out.print("请输入日期:");
day = input.nextInt();
sum = getDay(year,month,day);
getWeek(sum);
}
else
{
System.out.println("欢迎下次使用");
System.exit(0);
}
}
}
}
java:升级版的日期查询
最新推荐文章于 2024-06-21 21:40:52 发布