查询日历,万年历查询,日历格式JAVA原代码
- 格式:doc
- 大小:53.00 KB
- 文档页数:6
import java.util.Scanner;
public class Kaoshi {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入年份:");
int year = input.nextInt();
System.out.println("请输入月份:");
int month = input.nextInt();
int monthday = 0, day;
int aa[] = new int[12];
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { aa[0] = 31;aa[1] = 29;aa[2] = 31;aa[3] = 30;aa[4] = 31; aa[05] = 30;aa[6] = 31;aa[7] = 31;aa[8] = 30;aa[9] = 31;
aa[10] = 30;aa[11] = 31;
day = aa[month - 1];
for (int a2 = 0; a2 < month - 1; a2++) {
monthday += aa[a2];
}
} else {
aa[0] = 31;aa[1] = 28;aa[2] = 31;aa[3] = 30;aa[4] = 31; aa[05] = 30;aa[6] = 31;aa[7] = 31;aa[8] = 30;aa[9] = 31;
aa[10] = 30;aa[11] = 31;
day = aa[month - 1];
for (int a2 = 0; a2 < month - 1; a2++) {
monthday += aa[a2];
}
}
int yearday = 0;
for (int a1 = 1900; a1 < year; a1++) {
if (a1 % 4 == 0 && a1 % 100 != 0 || a1 % 400 == 0) { yearday += 366;
} else {
yearday += 365;
}
}
int totalday = yearday + monthday;
int week = totalday % 7 + 1;
switch (week) {
case 7:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("1\t2\t3\t4\t5\t6\t7\n8\t9\t10\t11\t12\t13\
t14\n15\t16\t17\t18\t19\t20\t21\n22\t23\t24\t25\t26\t27\t28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("1\t2\t3\t4\t5\t6\t7\n8\t9\t10\t11\t12\t13\ t14\n15\t16\t17\t18\t19\t20\t21\n22\t23\t24\t25\t26\t27\t28\n29") ;
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("1\t2\t3\t4\t5\t6\t7\n8\t9\t10\t11\t12\t13\ t14\n15\t"+
"16\t17\t18\t19\t20\t21\n22\t23\t24\t25\t26\t27\t28\n29\t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("1\t2\t3\t4\t5\t6\t7\n8\t9\t10\t11\t12\t13\ t14\n15\t16\t17\t18\t19\t20\t21\n22\t23\t24\t25\t26\t27\t28\n29\t 30\t31");
break;
}
break;
case 1:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t1\t2\t3\t4\t5\t6\n7\t8\t9\t10\t11\t12\t1 3\n14\t15\t16\t17\t18\t19\t20\n21\t22\t23\t24\t25\t26\t27\n28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t1\t2\t3\t4\t5\t6\n7\t8\t9\t10\t11\t12\t1 3\n14\t15\t16\t17\t18\t19\t20\n21\t22\t23\t24\t25\t26\t27\n28\t29 ");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t1\t2\t3\t4\t5\t6\n7\t8\t9\t10\t11\t12\t1 3\n14\t15\t16\t17\t18\t19\t20\n21\t22\t23\t24\t25\t26\t27\n28\t29 \t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t1\t2\t3\t4\t5\t6\n7\t8\t9\t10\t11\t12\t1 3\n14\t15\t16\t17\t18\t19\t20\n21\t22\t23\t24\t25\t26\t27\n28\t29 \t30\t31");
break;
}
break;
case 2:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.ou.println("\t\t1\t2\t3\t4\t5\n6\t7\t8\t9\t10\t11\t12\n 13\t14\t15\t16\t17\t18\t19\n20\t21\t22\t23\t24\t25\t26\n27\t28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t1\t2\t3\t4\t5\n6\t7\t8\t9\t10\t11\t12\ n13\t14\t15\t16\t17\t18\t19\n20\t21\t22\t23\t24\t25\t26\n27\t28\t 29");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.ou.println("\t\t1\t2\t3\t4\t5\n6\t7\t8\t9\t10\t11\t12\n 13\t14\t15\t16\t17\t18\t19\n20\t21\t22\t23\t24\t25\t26\n27\t28\t2 9\t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t1\t2\t3\t4\t5\n6\t7\t8\t9\t10\t11\t12\ n13\t14\t15\t16\t17\t18\t19\n20\t21\t22\t23\t24\t25\t26\n27\t28\t 29\t30\t31");
break;}
case 3:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t1\t2\t3\t4\n5\t6\t7\t8\t9\t10\t11\n1 2\t13\t14\t15\t16\t17\t18\n19\t20\t21\t22\t23\t24\t25\n26\t27\t28 ");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t1\t2\t3\t4\n5\t6\t7\t8\t9\t10\t11\n1 2\t13\t14\t15\t16\t17\t18\n19\t20\t21\t22\t23\t24\t25\n26\t27\t28 \t29");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t1\t2\t3\t4\n5\t6\t7\t8\t9\t10\t11\n1 2\t13\t14\t15\t16\t17\t18\n19\t20\t21\t22\t23\t24\t25\n26\t27\t28 \t29\t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.ou.println("\t\t\t1\t2\t3\t4\n5\t6\t7\t8\t9\t10\t11\n12 \t13\t14\t15\t16\t17\t18\n19\t20\t21\t22\t23\t24\t25\n26\t27\t28\ t29\t30\t31");
break;
}
break;
case 4:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t1\t2\t3\n4\t5\t6\t7\t8\t9\t10\n11\ t12\t13\t14\t15\t16\t17\n18\t19\t20\t21\t22\t23\t24\n25\t26\t27\t 28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t1\t2\t3\n4\t5\t6\t7\t8\t9\t10\n11\ t12\t13\t14\t15\t16\t17\n18\t19\t20\t21\t22\t23\t24\n25\t26\t27\t 28\t29");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t1\t2\t3\n4\t5\t6\t7\t8\t9\t10\n11\ t12\t13\t14\t15\t16\t17\n18\t19\t20\t21\t22\t23\t24\n25\t26\t27\t 28\t29\t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t1\t2\t3\n4\t5\t6\t7\t8\t9\t10\n11\ t12\t13\t14\t15\t16\t17\n18\t19\t20\t21\t22\t23\t24\n25\t26\t27\t 28\t29\t30\t31");
break;
}
break;
case 5:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t1\t2\n3\t4\t5\t6\t7\t8\t9\n10\t1 1\t12\t13\t14\t15\t16\n17\t18\t19\t20\t21\t22\t23\n24\t25\t26\t27 \t28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t1\t2\n3\t4\t5\t6\t7\t8\t9\n10\t1 1\t12\t13\t14\t15\t16\n17\t18\t19\t20\t21\t22\t23\n24\t25\t26\t27 \t28\t29");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t1\t2\n3\t4\t5\t6\t7\t8\t9\n10\t1 1\t12\t13\t14\t15\t16\n17\t18\t19\t20\t21\t22\t23\n24\t25\t26\t27 \t28\t29\t30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t1\t2\n3\t4\t5\t6\t7\t8\t9\n10\t1 1\t12\t13\t14\t15\t16\n17\t18\t19\t20\t21\t22\t23\n24\t25\t26\t27 \t28\t29\t30\n31");
break;
}
break;
case 6:
switch (day) {
case 28:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t\t1\n2\t3\t4\t5\t6\t7\t8\n9\t10\ t11\t12\t13\t14\t15\n16\t17\t18\t19\t20\t21\t22\n23\t24\t25\t26\t 27\t28");
break;
case 29:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t\t1\n2\t3\t4\t5\t6\t7\t8\n9\t10\ t11\t12\t13\t14\t15\n16\t17\t18\t19\t20\t21\t22\n23\t24\t25\t26\t 27\t28\t29");
break;
case 30:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t\t1\n2\t3\t4\t5\t6\t7\t8\n9\t10\ t11\t12\t13\t14\t15\n16\t17\t18\t19\t20\t21\t22\n23\t24\t25\t26\t 27\t28\t29\n30");
break;
case 31:
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
System.out.println("\t\t\t\t\t\t1\n2\t3\t4\t5\t6\t7\t8\n9\t10\ t11\t12\t13\t14\t15\n16\t17\t18\t19\t20\t21\t22\n23\t24\t25\t26\t 27\t28\t29\n30\t31");
break;
}
break;
}
}
}。