




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、.Java 實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)日期:2011年10月17日 實(shí)驗(yàn)機(jī)房與機(jī)號: 實(shí)驗(yàn)班級: 組員姓名學(xué)號: 指導(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(請輸入密碼:);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 萬年歷(3) 程序代碼import java.text.SimpleDateFormat;import java.util.*;public class CalendarAutopublic static void main(String args)System.out.println(請輸入年月(格式:年 月):);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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 汽車使用與維護(hù) 課件 項(xiàng)目二 行駛系統(tǒng)的使用與維護(hù)
- 2025年電動(dòng)機(jī)油泵項(xiàng)目可行性研究報(bào)告
- 2025年生物質(zhì)氣化機(jī)組項(xiàng)目可行性研究報(bào)告
- 2025年燃?xì)獠柙t項(xiàng)目可行性研究報(bào)告
- 南京醫(yī)科大學(xué)康達(dá)學(xué)院《海洋地理學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 吉林建筑科技學(xué)院《基礎(chǔ)醫(yī)學(xué)創(chuàng)新實(shí)驗(yàn)(2)》2023-2024學(xué)年第一學(xué)期期末試卷
- 滿洲里俄語職業(yè)學(xué)院《應(yīng)用化學(xué)專業(yè)外語》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025春新版一年級語文下冊期末練習(xí):口語交際專項(xiàng)
- 信陽農(nóng)林學(xué)院《復(fù)合材料成型工藝及設(shè)備》2023-2024學(xué)年第二學(xué)期期末試卷
- 新鄉(xiāng)工程學(xué)院《工筆人物寫生與創(chuàng)作》2023-2024學(xué)年第二學(xué)期期末試卷
- 6S組織架構(gòu)及內(nèi)容
- 《學(xué)前兒童衛(wèi)生保健》 課件 7.1 托幼園所的生活制度(課件)
- 2022年管理類聯(lián)考綜合能力(199)真題及答案解析0001
- 《人工智能技術(shù)基礎(chǔ)》課件 第3章 卷積神經(jīng)網(wǎng)絡(luò)
- 模擬訓(xùn)練中的作戰(zhàn)環(huán)境構(gòu)建
- 自考《13180操作系統(tǒng)》考前強(qiáng)化練習(xí)試題庫及答案
- 永久不能過戶的房屋買賣合同
- 中央空調(diào)維護(hù)保養(yǎng)服務(wù)投標(biāo)方案(技術(shù)方案)
- 華能廣東汕頭海上風(fēng)電有限責(zé)任公司招聘真題
- 2024年中考數(shù)學(xué)《二次函數(shù)的圖象與性質(zhì)》真題含解析
- 2024 NCCN指南:造血生長因子指南更新要點(diǎn)及治療方案解讀
評論
0/150
提交評論