「java编程万年历」java编程万年历能显示二十四节气

博主:adminadmin 2022-12-21 17:39:11 52

今天给各位分享java编程万年历的知识,其中也会对java编程万年历能显示二十四节气进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用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;ix;i++)

{System.out.print(" "); }

for(i=x;ix+y;i++)

a[i]=i-x+1;

for(i=x;ix+y;i++)

{

if ((i%7==0)(i0))

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;iyear;i++)

{if((i%4==0 i%100!=0)||(i%400==0))

y++;}

y=y%7;

for(i=1;i13;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;}

}

}

}

}

6

用Java编写一个万年历

G 年代标志符

y 年

M 月

d 日

h 时 在上午或下午 (1~12)

H 时 在一天中 (0~23)

m 分

s 秒

S 毫秒

E 星期

D 一年中的第几天

F 一月中第几个星期几

w 一年中第几个星期

W 一月中第几个星期

a 上午 / 下午 标记符

k 时 在一天中 (1~24)

K 时 在上午或下午 (0~11)

z 时区

参考地址:

如何用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.输出当月日历表,逢星期六换行

*/

import java.util.Scanner;

class FindMonthList {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入年份:");

        int year = sc.nextInt();            //年份

        if (year  1) {                        //判断非法输入年份

            System.out.println("输入错误!");

            return;

        }

        System.out.println("请输入月份:");

        int month = 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天

        int beforeYearTotalDay = ((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数组

        int beforeMonthTotalDay = 0;                                    //定义本年当月之前月份的总天数

        if (year % 400 == 0 || (year % 100 != 0  year % 4 == 0)) {    //判断当前年份是否是闰年

            for (int i = 0 ; i  month ; i ++ ) {    //for循环计算当月之前总天数

                //计算当前月份之前的所有天数

                beforeMonthTotalDay = beforeMonthTotalDay + arrLeapYear[i];

            }

            //判断当月1日是星期几

            int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;

            int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日

            for (int i = 0 ; i  (week - 1 + 7) % 7 ; i ++) {    //如果写成i  (week-1)会出现i-1的情况

                System.out.print("    ");//输出开头空白

            }

            for (int i = 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 (int i = 0 ; i  month ; i ++ ) {    //for循环计算出当月之前月份总天数

                beforeMonthTotalDay = beforeMonthTotalDay + arrNormalYear[i];

            }

            //判断当月1日是星期几

            int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;

            int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日

            for (int i = 0 ; i  (week - 1 + 7) % 7 ; i ++) {    //如果写成i  (week-1)会出现i-1的情况

                System.out.print("    ");//输出开头空白

            }

            for (int i = 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.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编写一个多功能万年历程序

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编写万年历!

/*

题目:输出任意年份任意月份的日历表(公元后)

思路:

    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.输出当月日历表,逢星期六换行

*/

import java.util.Scanner;

class FindMonthList {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入年份:");

        int year = sc.nextInt();            //年份

        if (year  1) {                        //判断非法输入年份

            System.out.println("输入错误!");

            return;

        }

        System.out.println("请输入月份:");

        int month = 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天

        int beforeYearTotalDay = ((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数组

        int beforeMonthTotalDay = 0;                                    //定义本年当月之前月份的总天数

        if (year % 400 == 0 || (year % 100 != 0  year % 4 == 0)) {    //判断当前年份是否是闰年

            for (int i = 0 ; i  month ; i ++ ) {    //for循环计算当月之前总天数

                //计算当前月份之前的所有天数

                beforeMonthTotalDay = beforeMonthTotalDay + arrLeapYear[i];

            }

            //判断当月1日是星期几

            int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;

            int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日

            for (int i = 0 ; i  (week - 1 + 7) % 7 ; i ++) {    //如果写成i  (week-1)会出现i-1的情况

                System.out.print("    ");//输出开头空白

            }

            for (int i = 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 (int i = 0 ; i  month ; i ++ ) {    //for循环计算出当月之前月份总天数

                beforeMonthTotalDay = beforeMonthTotalDay + arrNormalYear[i];

            }

            //判断当月1日是星期几

            int totalDay = beforeYearTotalDay + beforeMonthTotalDay + 1;

            int week = totalDay % 7;//已知1年1月1日是星期日,即模7得1对应的是星期日

            for (int i = 0 ; i  (week - 1 + 7) % 7 ; i ++) {    //如果写成i  (week-1)会出现i-1的情况

                System.out.print("    ");//输出开头空白

            }

            for (int i = 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编程万年历的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java编程万年历能显示二十四节气、java编程万年历的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-21,除非注明,否则均为首码项目网原创文章,转载请注明出处。