0_0_2595384_17583\Main.java:1: 进行语法解析时已到达文件结尾
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Calendar; /** * Hdu 2133 What day is it * <p>题目: <a href=http://acm.hdu.edu.cn/showproblem.php?pid=2133> * http://acm.hdu.edu.cn/showproblem.php?pid=2133 </a> </p> * @author ps */ public class Main { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = null; while((str = br.readLine()) != null){ String []list = str.split(" "); int year = Integer.parseInt(list[0]); int month = Integer.parseInt(list[1]); int day = Integer.parseInt(list[2]); if(year <=0 || year>=10000 ||month <=0 ||month>=13 ||day <=0 ||day>=32){ System.out.println("illegal"); continue; } //处理有些月没有31号的情况 if(4==month||6==month||9==month||11==month){ if(day>30){ System.out.println("illegal"); continue; } } //处理某些月有多余日如:2月在闰年时没有30/31在平年时没有29/30/31 if(2==month){ boolean isLeapYear = isLeapYear(year); if(isLeapYear && day>29){ System.out.println("illegal"); continue; }else if(!isLeapYear && day>28){ System.out.println("illegal"); continue; } } Calendar cal = Calendar.getInstance(); cal.setLenient(false); cal.set(year, month-1, day); int date = cal.get(Calendar.DAY_OF_WEEK); switch(date){ case Calendar.MONDAY: System.out.println("Monday"); break; case Calendar.TUESDAY: System.out.println("Tuesday"); break; case Calendar.WEDNESDAY: System.out.println("Wednesday"); break; case Calendar.THURSDAY: System.out.println("Thursday"); break; case Calendar.FRIDAY: System.out.println("Friday"); break; case Calendar.SATURDAY: System.out.println("Saturday"); break; case Calendar.SUNDAY: System.out.println("Sunday"); break; } } } /** * 判断是否是闰年 * @param year 年 * @return 是返回true,否返回false */ public static boolean isLeapYear(int year){ if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){ return true; } return false; } }
|