码迷,mamicode.com
首页 > 其他好文 > 详细

代码:准确算出用户输入的日期是星期几!

时间:2015-10-27 17:52:38      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:代码:准确算出用户输入的日期是星期几!

package myjavase;

import java.util.Scanner;


public class q3 {

public static void main(String[] args){

                Scanner inputday = new Scanner(System.in);

System.out.println("请输入要查询的日期:");

int q = inputday.nextInt();

int h;

h = (q + (26 * (m + 1)) / 10 + k + (k / 4) + (j / 4) + 5 * j) % 7 ;

if(h >= 0 && h < 7){

switch(h){

case 1:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期日。");

break;

case 2:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期一。");

break;

case 3:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期二。");

break;

case 4:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期三。");

break;

case 5:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期四。");

break;

case 6:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期五。");

break;

default:

System.out.println(year + " 年 " + m + " 月 " + q + " 日是星期六。");

break;

}

 }

inputyear.close();

inputmonth.close();

inputday.close();

     }

}

本文出自 “技术源于不断地发现与创新” 博客,请务必保留此出处http://vipfang.blog.51cto.com/149474/1706783

代码:准确算出用户输入的日期是星期几!

标签:代码:准确算出用户输入的日期是星期几!

原文地址:http://vipfang.blog.51cto.com/149474/1706783

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!