输入年、月、日,计算其为星期几
来源:互联网 发布:淘宝网手机修改密码 编辑:程序博客网 时间:2024/06/10 00:53
/*Enter year:(e.g., 2012): 2015Enter month: 1-12: 1Enter the day of the month: 1-31: 25Day of the week is Sunday.Enter year:(e.g., 2012): 2012Enter month: 1-12: 5Enter the day of the month: 1-31: 12Day of the week is Saturday.*/import java.util.Scanner;public class DayOfTheWeek { public static void main (String[] args) { Scanner input = new Scanner(System.in); int h, q, m, j, k; /****************************************************** * h: is the day of the week. * q: is the day of month. * m: is the month. * j: is the century. * k: is the year of the century. ******************************************************/ System.out.print("Enter year:(e.g., 2012): "); j = input.nextInt(); System.out.print("Enter month: 1-12: "); m = input.nextInt(); if (m == 1 || m == 2) { if (m == 1) m = 13; else m = 14; k = (j - 1) % 100; j /= 100; } else { k = j % 100; j /= 100; } System.out.print("Enter the day of the month: 1-31: "); q = input.nextInt(); h = (q + 26 * (m + 1) / 10 + k + k / 4 + j / 4 + 5 * j) % 7; System.out.print("Day of the week is "); switch (h) { case 0: System.out.println("Saturday."); break; case 1: System.out.println("Sunday."); break; case 2: System.out.println("Monday."); break; case 3: System.out.println("Tuesday."); break; case 4: System.out.println("Wednesday."); break; case 5: System.out.println("Thursday."); break; case 6: System.out.println("Friday."); break; } }}
0 0
- 输入年、月、日,计算其为星期几
- 输入年、月、日计算是星期几
- C 已知1900年1月1日是星期一,输入某年某月某日,求星期几
- 16.根据输入的日期输出星期几(已知公元1年1月1日星期一)
- 2.计算出1900年1月1日至当前日期之间总共间隔多少天,将其除以7取余数,该结果即为当月第一天是星期几,按日历格式输出
- 若已知1800年1月1日为星期3,则对于一个给定的年份和月份,输出这个月的最后一天是星期几。
- 已知1990年1月1号星期1.求出输入的年月日是星期几
- 输入任意日期计算星期几
- js操作时间(年-月-日 时-分-秒 星期几)
- 如何获取年、月、日、时、分、秒、星期几等
- iphone 输出如2010年2月25日星期几的时间格式 NSDate
- jsp页面格式化时间(星期几)(×××年×××月×××日。。。)
- 按年月日星期几的形式输出日期格式
- Android获取公历年/月/日/星期 + 农历月/日
- NSDate 年 月 日 星期 毫秒数
- 获取当天的年,月,日,星期。
- 转换日期格式 年/月/日 /星期
- 给定出生日,计算与此对应的是星期几。
- select、poll、epoll之间的区别总结[整理]
- POJ 2503 Babelfish qsort+bserach OR 字典树
- 图片缩放显示(UIViewContentModeScaleAspectFit) 要 从顶部开始显示的解决方法
- 继承QGraphicsItem 编译错误:error: no member named 'staticMetaObject' in 'QGraphicsItem'; did you mean sim
- Masonry入门教程
- 输入年、月、日,计算其为星期几
- 【Android实战】Bitmap图片的截屏、模糊处理、传递、使用
- RedHat 5.9安装R语言 R-2.13.0
- 开发自己的Openfire插件
- leetcode:Reverse Nodes in k-Group
- 通过RTLabel、RCLabel、FTCoreText及webView结合SDWebImage等4种方式实现左滑或下拉中cell中图文混排使用场景方案
- Android内存分析工具(二):DDMS
- Hashtable与hashmap 比较
- 缓存算法及Redis、Memcached、Guava、Ehcache中的算法