java求13号星期五
2022/2/2 20:42:25
本文主要是介绍java求13号星期五,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
看到外国人怕13号和星期五重叠,于是想看看什么时候会重叠,但没有现成的,于是写了点代码算了一下
public class Firday13 { public static int dx[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; public static int dy[] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 }; /** *闰年判断 */ public static boolean isYun(Integer year){ if (year%400 == 0 ||(year%4 == 0 && year%100 == 0) ){ return true; }else { return false; } } public static void firday(Integer year ,Integer week){ int a[] ; //循环月份 if (isYun(year)){ a = dy; }else { a = dx; } for (int i = 1; i < 12; i++) { for (int j = 1; j <= a[i]; j++,week++) { if (week>7){ week = week%7; } if (week == 5 && j == 13){ System.out.println(year+"年"+i+"月"+j+"日"+"是星期五"); } } } } /** * 0是星期天,返回星期几 */ public static int getWeek(int year){ Calendar calendar = Calendar.getInstance(); calendar.set(year,0,1); int x = calendar.get(calendar.DAY_OF_WEEK)-1; return x; } public static void main(String[] args) { for (int i = 1990; i <2100 ; i++) { firday(i,getWeek(i)); } } }
看了两年是准的,一年一两次出现
这篇关于java求13号星期五的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-03万字长文聊聊Web3的组成架构
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?