急求java万年历源代码!!!
展开全部
以前写过的一个:
import java.util.*;
import javax.management.RuntimeErrorException;
public class PrintCalendar {
public static void main(String[] args) {
System.out.println("**************欢迎使用万年历************");
int year = 2011;
int month = 0;
int day = 0;
int sumdays = 0;
int yearday = 0;
int monthday = 0;
int week = 0;
int weekday = 0;
String answer;
Scanner input = new Scanner(System.in);
System.out.print("请输入月份:");
month = input.nextInt();
if (month <= 0 || month > 12) {
throw new RuntimeErrorException(null, "月份输入错误");
} else {
boolean isRn = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
if (month == 1 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12) {
day = 31;
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
day = 30;
} else if (month == 2 && isRn == true) {
day = 29;
} else {
day = 28;
}
for (int i = 1800; i < year; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
yearday = yearday + 366;
} else {
yearday = yearday + 365;
}
}
for (int n = 1; n < month; n++) {
if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10
|| n == 12) {
monthday = monthday + 31;
} else if (n == 4 || n == 6 || n == 9 || n == 11) {
monthday = monthday + 30;
} else if (n == 2 && isRn == true) {
monthday = monthday + 29;
} else {
monthday = monthday + 28;
}
}
sumdays = yearday + monthday;
week = 1 + sumdays % 7;
System.out.println("日\t一\t二\t三\t四\t五\t六");
if (week != 7) {
for (int j = 0; j < week; j++) {
System.out.print("\t");
}
}
for (int k = 1; k <= day; k++) {
weekday = (sumdays - 1 + k) % 7 + 1;
if (weekday == 6) {
System.out.print(k + "\n");
} else {
System.out.print(k + "\t");
}
}
}
}
}
import java.util.*;
import javax.management.RuntimeErrorException;
public class PrintCalendar {
public static void main(String[] args) {
System.out.println("**************欢迎使用万年历************");
int year = 2011;
int month = 0;
int day = 0;
int sumdays = 0;
int yearday = 0;
int monthday = 0;
int week = 0;
int weekday = 0;
String answer;
Scanner input = new Scanner(System.in);
System.out.print("请输入月份:");
month = input.nextInt();
if (month <= 0 || month > 12) {
throw new RuntimeErrorException(null, "月份输入错误");
} else {
boolean isRn = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
if (month == 1 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12) {
day = 31;
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
day = 30;
} else if (month == 2 && isRn == true) {
day = 29;
} else {
day = 28;
}
for (int i = 1800; i < year; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
yearday = yearday + 366;
} else {
yearday = yearday + 365;
}
}
for (int n = 1; n < month; n++) {
if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10
|| n == 12) {
monthday = monthday + 31;
} else if (n == 4 || n == 6 || n == 9 || n == 11) {
monthday = monthday + 30;
} else if (n == 2 && isRn == true) {
monthday = monthday + 29;
} else {
monthday = monthday + 28;
}
}
sumdays = yearday + monthday;
week = 1 + sumdays % 7;
System.out.println("日\t一\t二\t三\t四\t五\t六");
if (week != 7) {
for (int j = 0; j < week; j++) {
System.out.print("\t");
}
}
for (int k = 1; k <= day; k++) {
weekday = (sumdays - 1 + k) % 7 + 1;
if (weekday == 6) {
System.out.print(k + "\n");
} else {
System.out.print(k + "\t");
}
}
}
}
}
参考资料: http://zhidao.baidu.com/question/336840854.html?oldq=1
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询