importjava.util.*;publicclasslll{publicstaticvoidmain(String[]args){days(inty,intm,intd);}publicstaticintdays(inty,intm,intd){System.out.println("计算y年m月d日是该年的第几...
import java.util.*;
public class lll {
public static void main (String[] args) {
days(int y,int m,int d);
}
public static int days(int y,int m,int d){
System.out.println ("计算y年m月d日是该年的第几天");
int i;//i用来判断是不是闰年
int j;//j用来判断在m月之前有几天,即到m月1日之前该年过了多少天
int k;//k用来计数总的是第几天
System.out.println ("请输入年份");
Scanner f=new Scanner(System.in);
y=f.nextInt();
System.out.println ("请输入月份");
m=f.nextInt();
System.out.println ("请输入日期");
d=f.nextInt();
if(y % 100==0){
if(y%400==0){
System.out.println ("该年有366天");
i=1;
}
}
else{
if (y%4==0){
System.out.println ("该年有366天");
i=1;
}
else{
i=0;
}
}
//以下按一年有365天做,最后加上i就可以
switch(m){
case 1:
j=0;
break;
case 2:
j=31;
break;
case 3:
j=59;
break;
case 4:
j=59+31;
break;
case 5:
j=90;
break;
case 6:
j=121;
break;
case 7:
j=121+30;
break;
case 8:
j=121+30+31;
break;
case 9:
j=121+30+62;
break;
case 10:
j=121+30+62+30;
break;
case 11:
j=121+92+30+31;
break;
case 12:
j=121+122+31+30;
break;
}
k=y+m+i+j;
System.out.print("这一天是该年的第"+k+"天");
}
}
后面的代码应该都没有问题,就是最前面引用方法的时候老是报错,求大神解答
展开