遍写个应用程序,输出某年某月的日历页,通过main方法的参数将年份和月份时间传递到程序中`

2024-11-22 15:56:46
推荐回答(2个)
回答1:

你的是伪代码么?我也不一个一个挑问题了,直接给个JAVA编译通过的代码你自己看看吧

package com.sooinn.tools.calendar;

import java.util.*;

public class CalendarPro {

/**
* @param int year, int month
*/
public static String getCalendar( int year, int month ) {

month = month - 1;
int day = 1;
String returnValue = null;

Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.SUNDAY);

calendar.set( year, month, day);

returnValue = "日 一 二 三 四 五 六";

int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;

int days = 0;
switch (month) {
case Calendar.JANUARY:
case Calendar.MARCH:
case Calendar.MAY:
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.OCTOBER:
case Calendar.DECEMBER:
days = 31;
break;
case Calendar.APRIL:
case Calendar.JUNE:
case Calendar.SEPTEMBER:
case Calendar.NOVEMBER:
days = 30;
break;
case Calendar.FEBRUARY:
days = 28;
if ( year%100 != 0 ) {
if ( year%4 == 0 ) {
days = 29;
}
} else {
if ( year/100%4 == 0 ) {
days = 29;
}
}
break;
}

String[] cal = new String[week+days];
for( int i = 0; i < week; i++ ) {
cal[i]=" ";
}

int n = 1;
for(int i = week; i < week+days; i++) {
cal[i]=String.valueOf(n++);
if ( cal[i].length() == 1 ) {
cal[i] = " " + cal[i];
}
}

for(int i=0;i if( i%7==0 ) {
returnValue = returnValue + "\n";
} else {
returnValue = returnValue + " ";
}
returnValue = returnValue + cal[i];
}

return returnValue;
}

public static void main(String[] args) {
System.out.println( CalendarPro.getCalendar( 1904, 2 ) );
}
}

回答2:

法身佛