谁能帮我解释下这个JAVA语言里的语句都是什么意思

来源:百度知道 编辑:UC知道 时间:2024/05/29 20:54:53
import java.util.Calendar;

public class OutputCalendar {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year = 0, month = 0;
if (args.length >= 2) {
try
{
year=Integer.parseInt(args[0]);
month=Integer.parseInt(args[1]);
}
catch(NumberFormatException e)
{
System.out.println("运行提供的年月信息不是合法的数值!");
System.exit(0);
}
}
else
{
System.out.println("没有提供输出处理的年月信息!");
System.exit(0);
}
Calendar cal=Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH,month-1);
if((year%4==0 && year%100!=0 || year % 400==0)&& month==2 )
days[1]++;
System.out.println("------------"+year+"年"+mon

输入一个年份和月份,输出这个月的日历,不过这里面的第一个for循环要有三个空格输出的才会正确,楼主可以试试。

比如传出2008 和 6 输出
------------2008年6月------------

SUN MON TUR WED THU FRI SAT
1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30

是一个日历

我做了点修改,可以不在运行的时候输入月份和年

package temp;

import java.util.Calendar;

public class temp {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year = 0, month = 0;
if (true) {
try {
year = Integer.parseInt("2008");
month = Integer.parseInt("6");
} catch (NumberFormatException e) {
System.out.println("ero11!");
System.exit(0);
}
} else