導航:首頁 > 編程語言 > 萬年歷java程序

萬年歷java程序

發布時間:2023-02-24 11:33:05

『壹』 java日歷查詢程序(萬年歷)

花了半個小時寫了一個望採納給好評。
import java.util.Scanner;

public class PrintCalendar {
/** Main method */
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// Prompt the user to enter year
System.out.print("Enter full year (e.g., 2001): ");
int year = input.nextInt();

// Prompt the user to enter month
System.out.print("Enter month in number between 1 and 12: ");
int month = input.nextInt();

// Print calendar for the month of the year
printMonth(year, month);
}

/** Print the calendar for a month in a year */
public static void printMonth(int year, int month) {
// Print the headings of the calendar
printMonthTitle(year, month);

// Print the body of the calendar
printMonthBody(year, month);
}

/** Print the month title, e.g., May, 1999 */
public static void printMonthTitle(int year, int month) {
System.out.println(" " + getMonthName(month)
+ " " + year);
System.out.println("-----------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}

/** Get the English name for the month */
public static String getMonthName(int month) {
String monthName = "";
switch (month) {
case 1: monthName = "January"; break;
case 2: monthName = "February"; break;
case 3: monthName = "March"; break;
case 4: monthName = "April"; break;
case 5: monthName = "May"; break;
case 6: monthName = "June"; break;
case 7: monthName = "July"; break;
case 8: monthName = "August"; break;
case 9: monthName = "September"; break;
case 10: monthName = "October"; break;
case 11: monthName = "November"; break;
case 12: monthName = "December";
}

return monthName;
}

/** Print month body */
public static void printMonthBody(int year, int month) {
// Get start day of the week for the first date in the month
int startDay = getStartDay(year, month);

// Get number of days in the month
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);

// Pad space before the first day of the month
int i = 0;
for (i = 0; i < startDay; i++)
System.out.print(" ");

for (i = 1; i <= numberOfDaysInMonth; i++) {
System.out.printf("%4d", i);

if ((i + startDay) % 7 == 0)
System.out.println();
}

System.out.println();
}

/** Get the start day of month/1/year */
public static int getStartDay(int year, int month) {
final int START_DAY_FOR_JAN_1_1800 = 3;
// Get total number of days from 1/1/1800 to month/1/year
int totalNumberOfDays = getTotalNumberOfDays(year, month);

// Return the start day for month/1/year
return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % 7;
}

/** Get the total number of days since January 1, 1800 */
public static int getTotalNumberOfDays(int year, int month) {
int total = 0;

// Get the total days from 1800 to 1/1/year
for (int i = 1800; i < year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;

// Add days from Jan to the month prior to the calendar month
for (int i = 1; i < month; i++)
total = total + getNumberOfDaysInMonth(year, i);

return total;
}

/** Get the number of days in a month */
public static int getNumberOfDaysInMonth(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12)
return 31;

if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;

if (month == 2) return isLeapYear(year) ? 29 : 28;

return 0; // If month is incorrect
}

/** Determine if it is a leap year */
public static boolean isLeapYear(int year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
}

『貳』 怎麼用JAVA編寫萬年歷!



/*
題目:輸出任意年份任意月份的日歷表(公元後)
思路:
1.已知1年1月1日是星期日,1%7=1對應的是星期日,2%7=2對應的是星期一,以此類推;
2.計算當年以前所有天數+當年當月1號之前所有天數;
a.年份分平年閏年,平年365天,閏年366天;
b.閏年的判斷方法year%400==0||(year%100!=0&&year%4==0)若為真,則為閏年否則為平年;
c.定義平年/閏年數組,包含各月天數;
d.遍歷數組求和,計算當年當月前總天數;
e.當年以前所有天數+當年當月前總天數+1即為1年1月1日到當年當月1日的總天數;
3.總天數對7取模,根據結果判斷當月1號是星期幾,輸出空白區域;
4.輸出當月日歷表,逢星期六換行
*/
importjava.util.Scanner;
classFindMonthList{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
System.out.println("請輸入年份:");
intyear=sc.nextInt();//年份
if(year<1){//判斷非法輸入年份
System.out.println("輸入錯誤!");
return;
}
System.out.println("請輸入月份:");
intmonth=sc.nextInt();//月份
if(month<1||month>12){//判斷非法輸入月份
System.out.println("輸入錯誤!");
return;
}
//輸出表頭
System.out.println("-------"+year+"年"+month+"月"+"-------");
System.out.println();
System.out.println("日一二三四五六");

//計算當前年份以前所有天數beforeYearTotalDay;每4年一個閏年,閏年366天,平年365天
intbeforeYearTotalDay=((year-1)/4*366)+(year-1-((year-1)/4))*365;
int[]arrLeapYear={0,31,29,31,30,31,30,31,31,30,31,30,31};//閏年各月天數int數組
int[]arrNormalYear={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年各月天數int數組
intbeforeMonthTotalDay=0;//定義本年當月之前月份的總天數
if(year%400==0||(year%100!=0&&year%4==0)){//判斷當前年份是否是閏年
for(inti=0;i<month;i++){//for循環計算當月之前總天數
//計算當前月份之前的所有天數
beforeMonthTotalDay=beforeMonthTotalDay+arrLeapYear[i];
}
//判斷當月1日是星期幾
inttotalDay=beforeYearTotalDay+beforeMonthTotalDay+1;
intweek=totalDay%7;//已知1年1月1日是星期日,即模7得1對應的是星期日
for(inti=0;i<(week-1+7)%7;i++){//如果寫成i<(week-1)會出現i<-1的情況
System.out.print("");//輸出開頭空白
}
for(inti=1;i<=arrLeapYear[month];i++){//for循環輸出各月天數
System.out.print(i+"");
if(i<10){//小於10的數補一個空格,以便列印整齊
System.out.print("");
}
if(i%7==((7-(week-1))%7)||i==arrLeapYear[month]){//每逢星期六/尾數換行
System.out.println();
}
}

}else{//不是閏年就是平年
for(inti=0;i<month;i++){//for循環計算出當月之前月份總天數
beforeMonthTotalDay=beforeMonthTotalDay+arrNormalYear[i];
}
//判斷當月1日是星期幾
inttotalDay=beforeYearTotalDay+beforeMonthTotalDay+1;
intweek=totalDay%7;//已知1年1月1日是星期日,即模7得1對應的是星期日
for(inti=0;i<(week-1+7)%7;i++){//如果寫成i<(week-1)會出現i<-1的情況
System.out.print("");//輸出開頭空白
}
for(inti=1;i<=arrNormalYear[month];i++){//for循環輸出各月天數
System.out.print(i+"");
if(i<10){//小於10的數補一個空格,以便列印整齊
System.out.print("");
}
if(i%7==((7-(week-1))%7)||i==arrNormalYear[month]){//每逢星期六/尾數換行
System.out.println();
}
}
}
}
}

效果:

『叄』 萬年歷JAVA程序上機

我這里兩個類,你跑起來看看,一個是計算農歷的,一個是拿來顯示的。

import java.util.*;
/**
* 農歷計算
*
* @author xysource
*
*/
public class LauarUtil
{

private static String[] daySTrPreArray = { "初", "十", "廿", "卅", " " };

/**
* 月份
*/
private static String[] dayStrArray = { "", "一", "二", "三", "四", "五", "六",
"七", "八", "九", "十", "十一", "十二" };

// private static String[] weekStrArray = { "", "日", "一", "二", "三", "四",
// "五", "六" };

final static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,
0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,
0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950,
0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260,
0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0,
0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40,
0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,
0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,
0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,
0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,
0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0,
0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65,
0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0,
0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,
0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };

final public static int lYearDays(int y)// ====== 傳回農歷 y年的總天數
{
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1)
{
if ((lunarInfo[y - 1900] & i) != 0)
sum += 1;
}
return (sum + leapDays(y));
}

final public static int leapDays(int y)// ====== 傳回農歷 y年閏月的天數
{
if (leapMonth(y) != 0)
{
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
}
else
return 0;
}

final public static int leapMonth(int y)// ====== 傳回農歷 y年閏哪個月 1-12 , 沒閏傳回 0
{
return (int) (lunarInfo[y - 1900] & 0xf);
}

final public static int monthDays(int y, int m)// ====== 傳回農歷 y年m月的總天數
{
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}

final public static String AnimalsYear(int y)// ====== 傳回農歷 y年的生肖
{
final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龍", "蛇",
"馬", "羊", "猴", "雞", "狗", "豬" };
return Animals[(y - 4) % 12];
}

final public static String cyclicalm(int num)// ====== 傳入 月日的offset 傳回干支,
// 0=甲子
{
final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",
"辛", "壬", "癸" };
final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",
"未", "申", "酉", "戌", "亥" };
return (Gan[num % 10] + Zhi[num % 12]);
}

final public static String cyclical(int y)// ====== 傳入 offset 傳回干支, 0=甲子
{
int num = y - 1900 + 36;
return (cyclicalm(num));
}

final public long[] Lunar(int y, int m)// 傳出農歷.year0 .month1 .day2
// .yearCyl3
// .monCyl4
// .dayCyl5 .isLeap6
{
final int[] year20 = new int[] { 1, 4, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
final int[] year19 = new int[] { 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
final int[] year2000 = new int[] { 0, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(1900, 1, 31);
Date objDate = new Date(y, m, 1);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
if (y < 2000)
offset += year19[m - 1];
if (y > 2000)
offset += year20[m - 1];
if (y == 2000)
offset += year2000[m - 1];
nongDate[5] = offset + 40;
nongDate[4] = 14;

for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 閏哪個月
nongDate[6] = 0;

for (i = 1; i < 13 && offset > 0; i++)
{
// 閏月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}

// 解除閏月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}

if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}

final public static long[] calElement(int y, int m, int d)
// 傳出y年m月d日對應的農歷.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6
{
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(0, 0, 31);
Date objDate = new Date(y - 1900, m - 1, d);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
nongDate[5] = offset + 40;
nongDate[4] = 14;

for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 閏哪個月
nongDate[6] = 0;

for (i = 1; i < 13 && offset > 0; i++)
{
// 閏月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}

// 解除閏月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}

if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}

public static String getchina(int day)
{
if (day == 10)
return "初十";
if (day == 20)
return "二十";
if (day == 30)
return "三十";
String a = daySTrPreArray[(int) ((day) / 10)];
//System.out.println(a);
a += dayStrArray[(int) (day % 10)];
return a;
}

public static String getLauar(Calendar cld)
{
int year = cld.get(Calendar.YEAR);
int month = cld.get(Calendar.MONTH) + 1;
int day = cld.get(Calendar.DAY_OF_MONTH);

long[] lauarStrArray = calElement(year, month, day);
String monthStr = dayStrArray[(int) (lauarStrArray[1])];
return monthStr + "月" + getchina((int) (lauarStrArray[2]));//AnimalsYear(1989)+"年農歷" +
}

public static void main(String[] args)
{
Calendar cld = Calendar.getInstance();
// for (int i = 0; i < 145; i++) {
System.out.println(getLauar(cld));
// cld.add(Calendar.DAY_OF_MONTH, 1);
// }
}

}

『肆』 用JAVA編寫一個萬年歷

import java.io.*;
class putout{
public void putout(int f,int x,int y){
int i;
int a[]= new int[40];
System.out.println(" 日 一 二 三 四 五 六 "+" "+f+"月");
for (i=0;i<x;i++)
{System.out.print(" "); }
for(i=x;i<x+y;i++)
a[i]=i-x+1;
for(i=x;i<x+y;i++)
{
if ((i%7==0)&&(i>0))
System.out.print("\n");
if (a[i]<10)
System.out.print(" "+a[i]);
else System.out.print(" "+a[i]);
}
System.out.println("\n");
}
}

class st{
public static void main(String args[])throws IOException{
putout p=new putout();
int year,mouth,y=1,t,i;
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
System.out.print("請輸入一個年份:");
String s=in.readLine();
year=Integer.parseInt(s);
if((year%4==0 && year%100!=0)||(year%400==0))
mouth=1;
else
mouth=0;
y=year;
for(i=1;i<year;i++)
{if((i%4==0 && i%100!=0)||(i%400==0))
y++;}
y=y%7;
for(i=1;i<13;i++){
switch(i){
case 1: {p.putout(1,y,31);y=(y+31)%7;break;}
case 2: {p.putout(2,y,28+mouth);y=(y+28+mouth)%7;break;}
case 3: {p.putout(3,y,31);y=(y+31)%7;break;}
case 4: {p.putout(4,y,30);y=(y+30)%7;break;}
case 5: {p.putout(5,y,31);y=(y+31)%7;break;}
case 6: {p.putout(6,y,30);y=(y+30)%7;break;}
case 7: {p.putout(7,y,31);y=(y+31)%7;break;}
case 8: {p.putout(8,y,31);y=(y+31)%7;break;}
case 9: {p.putout(9,y,30);y=(y+30)%7;break;}
case 10: {p.putout(10,y,31);y=(y+31)%7;break;}
case 11: {p.putout(11,y,30);y=(y+30)%7;break;}
case 12: {p.putout(12,y,31);y=(y+31)%7;break;}
}
}
}
}

『伍』 編寫 萬年歷java代碼例如1900年一月一日是星期一。

importjava.util.Calendar;
importjava.util.Date;
importjava.util.Scanner;

publicclassMyCalendar
{
publicstaticvoidmain(String[]args)
{
Scannerscanner=newScanner(System.in);
Stringreg="^(\d+)[^\d]+((0?[1-9])|(1[012]))$";
while(true)
{
System.out.println("輸入年月(年和月用非數字隔開:如2015.1)(什麼都不輸入直接退出)");
Stringline=scanner.nextLine().trim();
if("".equals(line))
{
scanner.close();
break;
}
if(!line.matches(reg))
{
continue;
}
intyear=Integer.parseInt(line.replaceAll(reg,"$1"));
intmonth=Integer.parseInt(line.replaceAll(reg,"$2"));
System.out.println("日 一 二 三 四 五 六");
Calendarcalendar=Calendar.getInstance();
//這個月的1號是星期幾
calendar.set(year,month-1,1);
intday=calendar.get(Calendar.DAY_OF_WEEK);
intstart=Calendar.SUNDAY;
calendar.add(Calendar.DATE,-day+start);
while(start<day)
{
System.out.print(calendar.get(Calendar.DATE)+" ");
calendar.add(Calendar.DATE,1);
start++;
}
calendar.set(year,month-1,1);
Datenow=calendar.getTime();
calendar.set(year,month,1);
Datenext=calendar.getTime();
for(Datecur=now;cur.before(next);)
{
calendar.setTime(cur);
intx=calendar.get(Calendar.DATE);
Stringtmp=x<10?"0"+x:x+"";
System.out.print(tmp+" ");
if(calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY)
{
System.out.println();
}
calendar.add(Calendar.DATE,1);
cur=calendar.getTime();
}
calendar.add(Calendar.DATE,-1);
intto=calendar.get(Calendar.DAY_OF_WEEK);
intend=Calendar.SATURDAY;
while(to<end)
{
calendar.add(Calendar.DATE,1);
intx=calendar.get(Calendar.DATE);
Stringtmp=x<10?"0"+x:x+"";
System.out.print(tmp+" ");
to++;
}
System.out.println();
}
}
}

『陸』 JAVA編寫一個多功能萬年歷程序

import java.text.SimpleDateFormat; import java.util.Calendar; public class TestDate { public static final String[] weeks = { "日", "一", "二", "三", "四", "五", "六" }; public static void main(String[] args) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR,2011);//2011年 c.set(Calendar.MONTH,0);//java中Calendar類,月從0開始, 0代表一月 c.set(Calendar.DATE,1);//1號 int day = c.get(Calendar.DAY_OF_WEEK);//獲致是本周的第幾天地, 1代表星期天...7代表星期六 System.out.println(new SimpleDateFormat( "yyyy-MM-dd ").format(c.getTime())); System.out.println("星期" + weeks[day-1]); } } 把以上測試代碼寫作一個方法 方法的參數名為年月日, 即可。當然Calendar 還有很多功能,比如一周的第幾天,一年的第幾個月……

『柒』 用java語言編寫萬年歷

給你一個現成的,我自己寫的。

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;

public class WanNianLi extends JFrame implements ActionListener {
private static int year,month,days;
private JButton[] btn=new JButton[days];

WanNianLi() {
super("萬年歷");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout bl=new GridLayout(5,7);
JPanel pane=new JPanel();
pane.setLayout(bl);

for (int i=0;i<days;i++) {
int temp=i+1;
btn[i]=new JButton(""+temp);
btn[i].addActionListener(this);
pane.add(btn[i]);
}
setContentPane(pane);
pack();
setLookAndFeel();
setVisible(true);

}

public static void main(String[] args) {
if (args.length>0)
year=Integer.parseInt(args[0]);
else
year=1982;
if (args.length>1)
month=Integer.parseInt(args[1]);
else
month=1;
GetDays gd=new GetDays(year,month);
days=gd.getDays();
new WanNianLi();
}

public void actionPerformed(ActionEvent evt) {
Object src=evt.getSource();
for (int i=0;i<days;i++)
if (src==btn[i]) {
int day=i+1;
GetWeekday gw=new GetWeekday(year,month,day);
String str="";
switch (gw.getWeekday()) {
case 1:
str="天";
break;
case 2:
str="一";
break;
case 3:
str="二";
break;
case 4:
str="三";
break;
case 5:
str="四";
break;
case 6:
str="五";
break;
case 7:
str="六";
break;
}
setTitle(year+"年"+month+"月"+day+"日"+"星期"+str);
repaint();
}
}

private void setLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e){
System.out.print(e.toString());
}
}

}

//////////////
//獲取星期幾//
//////////////
class GetWeekday {
private Calendar cal=Calendar.getInstance();
private static int weekday;

public int getWeekday() {
return weekday;
}

GetWeekday(int y,int m,int d) {
cal.clear();
cal.set(Calendar.YEAR,y);
cal.set(Calendar.MONTH,m-1);
cal.set(Calendar.DAY_OF_MONTH,d);
weekday=cal.get(Calendar.DAY_OF_WEEK);
}
}

////////////////////
//獲取當前月的天數//
////////////////////
class GetDays {
private static int days;

public int getDays() {
return days;
}

GetDays(int y,int m) {
GregorianCalendar gc=new GregorianCalendar();

switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
case 2:
if (gc.isLeapYear(y))
days=29;
else
days=28;
break;
}
}
}

閱讀全文

與萬年歷java程序相關的資料

熱點內容
桌面文件全部加密 瀏覽:401
6s怎麼外接u盤需要什麼app 瀏覽:131
linux查看文件許可權命令 瀏覽:685
安卓手游存檔怎麼用 瀏覽:761
linuxyum安裝ftp 瀏覽:690
村委會主任可以推行政命令嗎 瀏覽:102
電腦文件夾封面多張圖片 瀏覽:263
網吧總伺服器叫什麼 瀏覽:922
多個演算法解決同一個問題 瀏覽:455
小車解壓後我的購車發票呢 瀏覽:977
做app開發用什麼雲伺服器 瀏覽:177
linux網卡子介面 瀏覽:985
21歲職高畢業學程序員怎麼學 瀏覽:321
vs如何對單個文件編譯 瀏覽:6
為什麼有的電腦不能安裝python 瀏覽:75
金蝶迷你版加密狗檢測到過期 瀏覽:186
硬體描述語言編譯結果 瀏覽:655
程序員逆天改命 瀏覽:19
金斗雲伺服器 瀏覽:447
港口工程pdf 瀏覽:770