JAVA基礎(chǔ)實(shí)驗(yàn)編程_第1頁
JAVA基礎(chǔ)實(shí)驗(yàn)編程_第2頁
免費(fèi)預(yù)覽已結(jié)束,剩余16頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Java 實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)日期:2011 年 10 月 17 日實(shí)驗(yàn)機(jī)房與機(jī)號(hào): _ 實(shí)驗(yàn)班級(jí): _組員姓名學(xué)號(hào):指導(dǎo)教師:劉壽強(qiáng)第三單元實(shí)驗(yàn)?zāi)康模赫莆贞愂雒嫦驅(qū)ο蟮乃枷?,通過創(chuàng)建類的實(shí)力來體現(xiàn)實(shí)驗(yàn)內(nèi)容:第三單元;實(shí)驗(yàn)步驟:3-2class DogStri ng color;int weight;public Dog(Stri ng color,i nt weight)this.color=color;this.weight=weight;public void showd()class CatString color;int weight;public Cat(String color,int

2、weight)this.color=color;this.weight=weight;public void showc()public class Apublic static void main(String args)Dog d1= new Dog( 黃色 ,100);Cat c1= new Cat( 白色 ,200);d1.showd();c1.showc();3-3class CarStri ng pi ng;double price;Stri ng date;public Car(Stri ng pin g,double price,Stri ng date) this.pi ng

3、=pi ng;this.price=price; this.date=date;public void show()public void qd()public void sc()3-4public void js()public class Apublic static void main( Stri ng args)Car car=new Car(奇瑞,3000,保修終生!);car.show();car.js();public class Con soleParamspublic static void main( Stri ng args) if (args .len gth20)el

4、se3-6class SExamstatic int num=0;public SExam()num+;public class StaticExampublic static void main(String args)SExam se1=new SExam();SExam se2=new SExam();SExam se3=new SExam();第四單元目的:掌握格式化轉(zhuǎn)換異常, 實(shí)驗(yàn)內(nèi)容:第四單元 步驟如下: public classNumberFormatExceptionText /* paramargs*/public static void main(String args)

5、/ TODOAuto-generated method stubint iArray=0,0;tryiArrayO=lnteger.parseInt (argsO);iArray1=lnteger.parseInt (args1);catch (ArrayIndexOutOfBoundsExceptione)System. out .pri ntl n(用戶輸入的數(shù)據(jù)不完整,程序使用默認(rèn)值代替:); catch (NumberFormatException e)System. out .println(用戶輸入的不全是數(shù)值型的數(shù)據(jù),程序使用默認(rèn)值替代:);System.out .pri ntl

6、n( iArray0+ +iArray1+ = +(iArray0+iArray1);froblems緲Javidoc , Uaclarati on Lons:ol花5_ _ ._ _ _CtJws. Ajpli cats. 6ti C: Fr or irri FIISE用戶輜入的數(shù)據(jù)不憲整,程序便用默認(rèn)值代替:O-KJ=Opublic class ArithmeticExcepti on Text /*paranargs*/public static void main( Stri ng args) / TODOAuto-generated method stub tryint a=args

7、. length ;int b=42/a; catch (ArithmeticException e)System. out .println(除數(shù)不能夠?yàn)榱惆。。?Kterm 1 ikatedL. Ar 1 tiune ti cExcept i on;! ext Java Appl 1 oit C: Pr3igrm Fileimportpublic class NegativeIndexExceptionDemo public int getNumberOfRandomIndex(int iArray)throws NegativeIndexException除數(shù)不能夠?yàn)榱惆Random

8、random=newRandom();int index=random.nextInt();if (index0)throw new NegativeIndexException( this .getClass().getName()+.getNumberOfRandomIndex(int ) 方法不能夠處理自己所拋出的異常:索引值 +index+ 產(chǎn)出異常 );index=index%iArray. length ;return iArrayindex;public static void main(String args) int iArray=0,1,3,4,5,6,7,8,9;int

9、randomNumber=0;try ran domNumber=ewNegativel ndexExceptio nDemo().getNumberOfRa ndomI ndex(iArray); catch (NegativeIndexException e)System. out .println(e+ nmian 方法有能力處理該異常 t);randomNumber=Mathround( float )(Math. random()*10);System.out .println(產(chǎn)生隨機(jī)結(jié)果為+randomNumber);public class NegativeindexExcep

10、tionextends Exceptionpublic Negative in dexExceptio n()super (); public Negative in dexExcepti on( Stri ng message) super (message);第五單元一、實(shí)驗(yàn)?zāi)康模菏煜ふ莆蛰斎胼敵隽鞫?、?shí)驗(yàn)內(nèi)容:第五單元三、實(shí)驗(yàn)步驟練習(xí) 5-1 校驗(yàn)用戶密碼格式(1)程序代碼public class CheckPWpublic static void main( Stri ng args)Scanner sca nner=new Sca nn er(System.i n);String i

11、n putStri ng=sca nner.n extL in e();Stri ng regular=Aa-zA-Z$a-zA-Z$_0-97,19;if(inputString.matches(regular)else(2)運(yùn)行結(jié)果圖 5-1練習(xí) 5-2 轉(zhuǎn)換中文格式日期( 1 )程序代碼public class ChineseDatepublic static void main(String args)Date date=new Date(10,9,2011);String dateFormatStr= 北京時(shí)間 :ntH:mm:ssntEntyyyy-M-dd;SimpleDateF

12、ormat simpleFormat=new SimpleDateFormat(dateFormatStr);(2)運(yùn)行結(jié)果圖 5-2練習(xí) 5-3 萬年歷( 3)程序代碼import java.util.*;public class CalendarAutopublic static void main(String args)Scanner scanner=new Scanner(System.in);int params=new int2;for(int i=0;i12)params1=params1%13;if(params10)params1=12+params1%13;Calenda

13、r calendar=Calendar.getInstance();calendar.set(params0,params1-1,1);int firstIndex=calendar.get(Calendar.DAY_OF_WEEK)-1;char title=日, 一 , 二, 三, 四, 五 , 六;int daysArray=new int67;int day=1;for(int i=firstIndex;i7;i+)daysArray0i=day+;for(int i=1;i6;i+)for(int j=0;jdaysOfMonth(params0,params1)i=6;break;daysArrayij=day+;for(int i=0;i7;i+)for(int i=0;i6;i+)for(int j=0;j7;j+)private static int daysOfMonth(int year,int month)switch(month)case 1:case 3:case 5:case 7:case

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論