java:升级版的日期查询

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);
			}
			

		}
		
	    
	    

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值