请各位java高手帮我改错,谢谢!
publicclassHeCalendar{intallday;Calendarcal;publicHeCalendar(intm,intn){int[]days={31...
public class HeCalendar
{
int allday;
Calendar cal;
public HeCalendar(int m,int n)
{
int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
cal=Calendar.getInstance();
cal.set(Calendar.YEAR, m);
cal.set(Calendar.MONTH,n-1);
cal.set(Calendar.DATE,1);
if((m%4==0 && m%100!=0 || m % 400==0)&& n==2 )
days[1]++;
allday=days[n-1];
}
public static void getYM(String stry,String strm)
{
int year=0,month=0;
try
{
year=Integer.parseInt(stry);
month=Integer.parseInt(strm);
}
catch(NumberFormatException e)
{
System.out.println("输入的年月信息不合法!");
}
System.out.println("year="+year+"month="+month);
}
public void print(int x,int y)
{
System.out.println("------------"+x+"年"+y+"月份------------\n");
System.out.println("SUN MON TUR WED THU FRI SAT");
int first=cal.get(Calendar.DAY_OF_WEEK);
int i=0;
for(i=1;i<first;i++)
System.out.print(" ");
for(i=1;i<=allday;i++)
{
if(i<10) System.out.print(" ");
System.out.print(" "+i);
System.out.print(" ");
if(first++%7==0)
System.out.println("\n ");
}
}
public static void main(String[]args)
{
if(args.length>=2)
{
getYM(args[0],args[1]);
}
else
{
System.out.println("运行时年月信息提供不全!");
}
HeCalendar myjava=new HeCalendar(year,month);
myjava.print(year,month);
}
} 展开
{
int allday;
Calendar cal;
public HeCalendar(int m,int n)
{
int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
cal=Calendar.getInstance();
cal.set(Calendar.YEAR, m);
cal.set(Calendar.MONTH,n-1);
cal.set(Calendar.DATE,1);
if((m%4==0 && m%100!=0 || m % 400==0)&& n==2 )
days[1]++;
allday=days[n-1];
}
public static void getYM(String stry,String strm)
{
int year=0,month=0;
try
{
year=Integer.parseInt(stry);
month=Integer.parseInt(strm);
}
catch(NumberFormatException e)
{
System.out.println("输入的年月信息不合法!");
}
System.out.println("year="+year+"month="+month);
}
public void print(int x,int y)
{
System.out.println("------------"+x+"年"+y+"月份------------\n");
System.out.println("SUN MON TUR WED THU FRI SAT");
int first=cal.get(Calendar.DAY_OF_WEEK);
int i=0;
for(i=1;i<first;i++)
System.out.print(" ");
for(i=1;i<=allday;i++)
{
if(i<10) System.out.print(" ");
System.out.print(" "+i);
System.out.print(" ");
if(first++%7==0)
System.out.println("\n ");
}
}
public static void main(String[]args)
{
if(args.length>=2)
{
getYM(args[0],args[1]);
}
else
{
System.out.println("运行时年月信息提供不全!");
}
HeCalendar myjava=new HeCalendar(year,month);
myjava.print(year,month);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询