欢迎来到天天文库
浏览记录
ID:17878378
大小:52.50 KB
页数:7页
时间:2018-09-08
《马俊-兰大java实验-04》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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("现在的时间是");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("数组下标越界异常");}}}//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
此文档下载收益归作者所有