日期:2014-05-20  浏览次数:20830 次

请问这个程序怎么运行不成呢?请高手指点,谢谢!
package javatest;

import java.util.*;

/**
 *
 * @author feifei
 */
public class JavaTest4 {
  public static void main(String args[]){
  int year,month;
  int d=0;
  int day=0;
  int days=0;
  input fymd=new input();
  int e;
  do{
  e=0;
  System.out.println("输入年:");
  year=fymd.input();
  System.out.println("输入月:");
  month=fymd.input();
  System.out.println("输入日:");
  day=fymd.input();
  if(year<0||month<0||month>30||day<0||day>31){
  System.out.println("输入错误!请重新输入!");
  e=1;
  }
  }
  while(e==1);
  for(int i=1;i<month;i++){
  switch(i){
  case1:
  case3:
  case5:
  case7:  
  case8:
  case10:
  case12:
  days=31;
  break;
  case4:
  case6:
  case9:
  case11:
  days=30;
  break;
  case2:
  if(year%400==0||(year%4==0&&year%100!=0)){
  days=29;  
  }else{
  days=28;
}
  break;
}
  d+=days;  
   
   
  }
System.out.println(year+"-"+month+"-"+day+"是一年当中的第"+(d+day)+"天!");
  }
  }
class input{
  public int input(){
  int value=0;  
  Scanner s=new Scanner(System.in);
  value=s.nextInt();
  return value;
  } 
   
}


------解决方案--------------------
/**
* 计算year年month月day日是星期几---蔡勒函数
* @param year
* @param month
* @param day
* @return
*/
public static int weekDay(int year,int month,int day)
{
if(month==1) month=13;
if(month==2) month=14;
int week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
return week+1;
}