資源描述:
《馬俊-蘭大java實驗-04》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、//CalendarTest.javaimportjava.text.*;importjava.util.*;classCalendarTest{publicstaticvoidmain(String[]args){Calendarcalendar=Calendar.getInstance();calendar.setTime(newDate());Stringyear=String.valueOf(calendar.get(Calendar.YEAR)),month=String.valueOf(calendar.
2、get(Calendar.MONTH)+1),day=String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)),weekday=String.valueOf(calendar.get(Calendar.DAY_OF_WEEK)-1);inthour=calendar.get(Calendar.HOUR_OF_DAY),minute=calendar.get(Calendar.MINUTE),second=calendar.get(Calendar.SECOND);Syst
3、em.out.println("現(xiàn)在的時間是");System.out.println(year+"年"+month+"月"+day+"日"+"星期"+weekday);System.out.println(hour+"時"+minute+"分"+second+"秒");calendar.set(2008,2,8);longtime2008=calendar.getTimeInMillis();calendar.set(2009,2,8);longtime2009=calendar.getTimeInMillis()
4、;longdays=(time2009-time2008)/(1000*60*60*24);System.out.println("2009年3月8日和2008年3月8日相隔"+days+"天");Datedate=newDate();SimpleDateFormatdateFm1=newSimpleDateFormat("EEEE-MMMM-dd-yyyy");System.out.println(dateFm1.format(date));DateFormatdateFm2=DateFormat.getDateT
5、imeInstance(DateFormat.SHORT,DateFormat.SHORT);System.out.println(dateFm2.format(date));}}//CatchException.javapublicclassCatchException{publicstaticvoidmain(String[]args){int[]myarr=newint[10];try{myarr[10]=10;}catch(ArrayIndexOutOfBoundsExceptione){System.out
6、.println("數(shù)組下標越界異常");}}}//ExceptionExample.javaclassNoLowerLetterextendsException{publicvoidprint(){System.out.printf("%c",'#');}}classNoDigitextendsException{publicvoidprint(){System.out.printf("%c",'#');}}classTest{voidprintLetter(charc)throwsNoLowerLetter{if
7、(c<'a'
8、
9、c>'z'){NoLowerLetternoLowerLetter=newNoLowerLetter();thrownoLowerLetter;}else{System.out.print(c);}}voidprintDigit(charc)throwsNoDigit{if(c<'1'
10、
11、c>'9'){NoDigitnoDigit=newNoDigit();thrownoDigit;}else{System.out.print(c);}}}publicclassExceptionExample{pub
12、licstaticvoidmain(Stringargs[]){Testt=newTest();for(inti=0;i<128;i++){try{t.printLetter((char)i);}catch(NoLowerLettere){e.print();}}for(inti=0;i<128;i++){try{t.printDigit((c