文件名称:简单的JAVA程序.
文件大小:2KB
文件格式:JAVA
更新时间:2011-09-28 04:46:27
程序
本章闰年.平年 判断.package cter;
import java.util.*;
public class dom6 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String yes;
do {
System.out.println("★★★★★★★★欢迎使用万年历★★★★★★★★");
System.out.println("请输入年:");
int nian = input.nextInt();
System.out.println("请输入月:");
int yue = input.nextInt();
System.out.println("请输入日");
int ri = input.nextInt();
boolean nian1; // 判断是否是润年!
if (nian % 4 == 0 && nian % 100 != 0 || nian % 400 == 0){ // 判断润年的条件
nian1 = true ;
System.out.println(nian +"年是润年!二月份有 29 天");
}else {
nian1 = false ;
System.out.println(nian +"年是平年!二月份有 28 天");
}
int sum = 0; //满年总天数
for (int i = 1900 ; i < nian ; i++){
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
sum = sum + 366 ;
}else {
sum = sum + 365 ;
}
}
System.out.println("距1900年1月1日有" + sum + "天!");
int ri1 = 0; // 输入的月份的天数;
switch (yue){
case 4:
case 6:
case 9:
case 11:
ri1 = 30;
break;
case 2:
if (nian1){
ri1 = 29;
}else {
ri1 = 28;
}
break;
default:
ri1 = 31;
}
int ri2 = 0;
int ri3 = 0;
for (int i = 1; i < yue ; i++){
switch (i){
case 4:
case 6:
case 9:
case 11:
ri3 = 30;
break;
case 2:
if (nian1){
ri3 = 29;
}else {
ri3 = 28;
}
break;
default:
ri3 = 31;
}
ri2 = ri2 +ri3;
}
System.out.println("距本年1月1日有" + ri2 + "天!");
int sum1 = sum + ri2; // 总天数;
int yue2 = (sum1 + ri) % 7;
System.out.println("\n今天是星期" + yue2);
System.out.println("\n星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
int yue3 = (sum1 + 1) % 7;
for (int i =1 ; i <= yue3 ; i++ ){
System.out.print("\t|");
}
for (int i = 1; i <= ri1; i++){
System.out.print(i + "\t|");
if((sum1 + i )% 7 == 6){
System.out.print("\n|");
}
}
System.out.print("\n是否继续