用Java判断某年某月有多少天 – 手机爱问

2024-12-11 15:33:50
推荐回答(1个)
回答1:

importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.util.Calendar;publicclassCCC{publicstaticvoidmain(String[]args)throwsIOException{System.out.println("请输入年月日,格式:yyyy-MM-dd");BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));Strings=br.readLine();Calendarc=Calendar.getInstance(java.util.Locale.CHINA);String[]sp=s.split("-");c.set(Calendar.YEAR,Integer.parseInt(sp[0]));c.set(Calendar.MONTH,Integer.parseInt(sp[1])-1);c.set(Calendar.DATE,Integer.parseInt(sp[2]));intwd=c.get(Calendar.DAY_OF_WEEK);Stringx="";switch(wd){case1:x="星期日";break;case2:x="星期一";break;case3:x="星期二";break;case4:x="星期三";break;case5:x="星期四";break;case6:x="星期五";break;case7:x="星期六";break;}System.out.println(s+"是:"+x);}}