万年历:输入要查看的年份,输出该年份的日历
实现代码:
package CJF;
import java.util.*;
public class ks {
public static void main(String[] args) {
int x = 3,n,m,y,r,k;
System.out.println("******您好,2016年华人款万年历,枫枫为您服务******");
System.out.println("**********************请输入查找年份********");
System.out.println();
Scanner input = new Scanner(System.in);
n = input.nextInt();
int cut = 365 * 3 + 366;
if(n >= 1997){
m = n - 1997;
int a = m / 4;
int b = m % 4;
x = (x + cut * a + b * 365) % 7;
}
else{
m = 1996 - n;
x =(366 - x + 2) % 7; // 先转换为1996年为基准年份
int a = m / 4;
int b = m % 4;
cut = (cut * a + b * 365) % 7;
x = (x - cut + 7) % 7;
}