




版權(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 DogString color;int weight;public Dog(String color,int weight)this.color=color;this.weight=weight;public void showd()System.out.println(這是體重為+weight+斤,+顏色為+color+的狗);class CatString col
2、or;int weight;public Cat(String color,int weight)this.color=color;this.weight=weight;public void showc()System.out.println(這是體重為+weight+斤,+顏色為+color+的貓);public class Apublic static void main(String args)Dog d1= new Dog(黃色,100);Cat c1= new Cat(白色,200);d1.showd();c1.showc(); 3-3class CarString ping;do
3、uble price;String date;public Car(String ping,double price,String date)this.ping=ping;this.price=price;this.date=date;public void show()System.out.println(ping+轎車,價(jià)格為+price+date);public void qd()System.out.println(汽車正在啟動(dòng));public void sc()System.out.println(汽車正在剎車);public void js()System.out.println(
4、汽車正在加速);public class Apublic static void main(String args)Car car=new Car(奇瑞,3000,保修終生!);car.show();car.js();3-4public class ConsoleParamspublic static void main(String args)if (args.length20)System.out.println(數(shù)值較大);elseSystem.out.println(數(shù)值較小或等于);3-6class SExamstatic int num=0;public SExam() num+;
5、public class StaticExampublic static void main(String args)SExam se1=new SExam();SExam se2=new SExam();SExam se3=new SExam();System.out.println(SExam.num+次);第四單元目的:掌握格式化轉(zhuǎn)換異常,實(shí)驗(yàn)內(nèi)容:第四單元步驟如下:public class NumberFormatExceptionText /* * param args */public static void main(String args) / TODO Auto-genera
6、ted method stubint iArray=0,0; try iArray0=Integer.parseInt(args0); iArray1=Integer.parseInt(args1);catch(ArrayIndexOutOfBoundsException e) System.out.println(用戶輸入的數(shù)據(jù)不完整,程序使用默認(rèn)值代替:); catch(NumberFormatException e) System.out.println(用戶輸入的不全是數(shù)值型的數(shù)據(jù),程序使用默認(rèn)值替代:); System.out.println(iArray0+iArray1+=+(i
7、Array0+iArray1);public class ArithmeticExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubtryint a=args.length;int b=42/a;catch(ArithmeticException e)System.out.println(除數(shù)不能夠?yàn)榱惆。?;import java.util.Random;public class NegativeIndexExceptionDemo publi
8、c int getNumberOfRandomIndex(int iArray)throws NegativeIndexExceptionRandom random=new Random();int index=random.nextInt();if(index0) throw new NegativeIndexException(this.getClass().getName()+.getNumberOfRandomIndex(int)方法不能夠處理自己所拋出的異常:索引值+index+產(chǎn)出異常); index=index%iArray.length;return iArrayindex;p
9、ublic static void main(String args) int iArray=0,1,3,4,5,6,7,8,9;int randomNumber=0;tryrandomNumber=new NegativeIndexExceptionDemo().getNumberOfRandomIndex(iArray);catch(NegativeIndexException e)System.out.println(e+nmian方法有能力處理該異常t);randomNumber=Math.round(float)(Math.random()*10);System.out.printl
10、n(產(chǎn)生隨機(jī)結(jié)果為+randomNumber);public class NegativeIndexException extends Exceptionpublic NegativeIndexException()super();public NegativeIndexException(String message)super(message);第五單元一、實(shí)驗(yàn)?zāi)康模菏煜ふ莆蛰斎胼敵隽鞫?shí)驗(yàn)內(nèi)容:第五單元三、實(shí)驗(yàn)步驟 練習(xí)5-1 校驗(yàn)用戶密碼格式(1) 程序代碼import java.util.Scanner;public class CheckPWpublic static void
11、main(String args)System.out.println(請(qǐng)輸入密碼:);Scanner scanner=new Scanner(System.in);String inputString=scanner.nextLine();String regular=a-zA-Z$_a-zA-Z$_0-97,19;if(inputString.matches(regular)System.out.println(密碼符合組合規(guī)律。);elseSystem.out.println(密碼不符合組合規(guī)律。);(2) 運(yùn)行結(jié)果圖5-1練習(xí)5-2 轉(zhuǎn)換中文格式日期(1) 程序代碼import jav
12、a.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Locale;public class ChineseDatepublic static void main(String args)Date date=new Date(10,9,2011);String dateFormatStr=北京時(shí)間:ntH:mm:ssntEntyyyy-M-dd;SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFor
13、matStr);System.out.println(simpleFormat.format(date);(2) 運(yùn)行結(jié)果圖5-2練習(xí)5-3 萬(wàn)年歷(3) 程序代碼import java.text.SimpleDateFormat;import java.util.*;public class CalendarAutopublic static void main(String args)System.out.println(請(qǐng)輸入年月(格式:年 月):);Scanner scanner=new Scanner(System.in);int params=new int2;for(int i=
14、0;i12)params1=params1%13;if(params10)params1=12+params1%13;Calendar 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
15、;i6;i+)for(int j=0;jdaysOfMonth(params0,params1)i=6;break;daysArrayij=day+;for(int i=0;i7;i+)System.out.print(titlei+t);System.out.println();for(int i=0;i6;i+)for(int j=0;j7;j+)if(daysArrayij!=0)System.out.print(daysArrayij+t);else System.out.print( t);System.out.println();private static int daysOfMonth(int year,int month)switch(month
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 綜合接入?yún)f(xié)議書
- 綠化修復(fù)協(xié)議書
- 配套公建協(xié)議書
- 競(jìng)拍保證協(xié)議書
- 浴足店合作合同協(xié)議書
- 英國(guó)數(shù)據(jù)協(xié)議書
- 老李離婚協(xié)議書
- 干砌石擋墻外包協(xié)議書
- 道閘安裝協(xié)議書
- 外立面改造安全協(xié)議書
- 2025年財(cái)務(wù)管理全球經(jīng)濟(jì)試題及答案
- 2025-2030年芳綸纖維行業(yè)市場(chǎng)深度調(diào)研及發(fā)展趨勢(shì)與投資研究報(bào)告
- 2024年濱州市沾化區(qū)區(qū)屬國(guó)有企業(yè)招聘考試真題
- 紡織機(jī)械操作知識(shí)掌握策略試題及答案
- 煙臺(tái)科目一試題及答案
- 2025年廣東佛山市三水海江建設(shè)投資有限公司招聘筆試參考題庫(kù)含答案解析
- 【高中英語(yǔ)】2025年高考英語(yǔ)作文預(yù)測(cè)(10大主題+55篇范文)下
- (完整)北京版小學(xué)英語(yǔ)1至6年級(jí)詞匯(帶音標(biāo))
- 服裝工藝(各工序)單價(jià)表
- 檢驗(yàn)員標(biāo)準(zhǔn)培訓(xùn)記錄
- 中國(guó)市場(chǎng)橄欖油與消費(fèi)者健康及使用需求聯(lián)合調(diào)研報(bào)告(共46頁(yè)).docx
評(píng)論
0/150
提交評(píng)論