(JAVA)使用DayCounter程序中的countDays()方法创建一个应用程序

来源:百度知道 编辑:UC知道 时间:2024/05/10 04:41:19
使用DayCounter程序中的countDays()方法创建一个应用程序,它显示指定年份中的每一天(从1月1日到12月31日)

public class useDayCounter
{
public static void main(String[] arguments)
{
int yearIn=2008; //初始设定年份
int monthIn=1;
if (arguments.length>0) //当arguments的元素大于0时执行下一条
monthIn=Integer.parseInt(arguments[0]); //调用parseInt,并将arguments的第0个元素传递给它 产生一个monthIn的值
if (arguments.length>1)
{
yearIn=Integer.parseInt(arguments[1]);
}
for (int i=1;i<13 ;i++ )
{System.out.print(i);
System.out.print("月");
}

for (int j=1; j<********;j++ )
{System.out.print(j);
System.out.println("日");
}

//System.out.println(monthIn+"/" + yearIn+" has "+countDays(monthIn,yearIn)+" days. ");//调用countDays方法
}
static int countDays (int month,int year){ //具体countDays的方法
int count = -1; //创建一

编程的要求是指定年份的每一天,所以不设计月… 下面是我写的:class useDayCounter{
public static void main(String[] arguments) {
int yearIn = 2008;
if (arguments.length > 0)
yearIn = Integer.parseInt(arguments[0]);//输入一个年份
for (int i =1;i< 13 ; i++ ){

for (int j =1;j<countDays(i,yearIn) + 1 ;j++ ){
System.out.print(i + "/" + j + "/" + yearIn + "\t");
}
}

}
static int countDays(int month,int year) {
int count = -1;
switch (month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
count = 31;
break;
case 4:
case 6:
case 9:
case 11:
count = 30;
break;
case 2:
if (year % 4 ==0)
count = 29;
else
count = 28;
if ((year % 100 == 0) & (year % 400 !=0))
count = 28;
}
return count;
}
}

for (int j=1; j=<useDayCounter.countDays (i,yearIn);j++ )
类名.静态方法名 调用静态