歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

JAVA基礎(chǔ)實驗編程

  • 資源ID:17804333       資源大?。?span id="1gtqdwi" class="font-tahoma">207.41KB        全文頁數(shù):10頁
  • 資源格式: DOC        下載積分:9.9積分
快捷下載 游客一鍵下載
會員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要9.9積分
郵箱/手機:
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機號,方便查詢和重復(fù)下載(系統(tǒng)自動生成)
支付方式: 支付寶    微信支付   
驗證碼:   換一換

 
賬號:
密碼:
驗證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會被瀏覽器默認打開,此種情況可以點擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標題沒有明確說明有答案則都視為沒有答案,請知曉。

JAVA基礎(chǔ)實驗編程

Java 實驗報告實驗日期:2011年10月17日 實驗機房與機號: 實驗班級: 組員姓名學(xué)號: 指導(dǎo)教師:劉壽強 第三單元實驗?zāi)康模赫莆贞愂雒嫦驅(qū)ο蟮乃枷?,通過創(chuàng)建類的實力來體現(xiàn)實驗內(nèi)容:第三單元;實驗步驟: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 color;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;double 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+"轎車,價格為"+price+date);public void qd()System.out.println("汽車正在啟動");public void sc()System.out.println("汽車正在剎車");public void js()System.out.println("汽車正在加速");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.length<2)return;int a=Integer.parseInt(args0);int b=Integer.parseInt(args1);int c;c=a+b;System.out.println(a+" +"+b+" ="+c);3-5import java.io.*;public class ExampleDpublic static void main(String args)int num=20;if(num>20)System.out.println("數(shù)值較大");elseSystem.out.println("數(shù)值較小或等于");3-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();System.out.println(SExam.num+"次");第四單元目的:掌握格式化轉(zhuǎn)換異常,實驗內(nèi)容:第四單元步驟如下:public class NumberFormatExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubint iArray=0,0; try iArray0=Integer.parseInt(args0); iArray1=Integer.parseInt(args1);catch(ArrayIndexOutOfBoundsException e) System.out.println("用戶輸入的數(shù)據(jù)不完整,程序使用默認值代替:"); catch(NumberFormatException e) System.out.println("用戶輸入的不全是數(shù)值型的數(shù)據(jù),程序使用默認值替代:"); System.out.println(iArray0+"+"+iArray1+"="+(iArray0+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ù)不能夠為零??!");import java.util.Random;public class NegativeIndexExceptionDemo public int getNumberOfRandomIndex(int iArray)throws NegativeIndexExceptionRandom random=new Random();int index=random.nextInt();if(index<0) 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 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.println("產(chǎn)生隨機結(jié)果為"+randomNumber);public class NegativeIndexException extends Exceptionpublic NegativeIndexException()super();public NegativeIndexException(String message)super(message);第五單元一、實驗?zāi)康模菏煜ふ莆蛰斎胼敵隽鞫?、實驗?nèi)容:第五單元三、實驗步驟 練習(xí)5-1 校驗用戶密碼格式(1) 程序代碼import java.util.Scanner;public class CheckPWpublic static void 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) 運行結(jié)果圖5-1練習(xí)5-2 轉(zhuǎn)換中文格式日期(1) 程序代碼import java.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="北京時間:ntH:mm:ssntEntyyyy-M-dd"SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr);System.out.println(simpleFormat.format(date);(2) 運行結(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=0;i<2&&scanner.hasNextInt();i+)paramsi=scanner.nextInt();if(params1>12)params1=params1%13;if(params1<0)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;i<7;i+)daysArray0i=day+;for(int i=1;i<6;i+)for(int j=0;j<7;j+)if(day>daysOfMonth(params0,params1)i=6;break;daysArrayij=day+;for(int i=0;i<7;i+)System.out.print(titlei+"t");System.out.println();for(int i=0;i<6;i+)for(int j=0;j<7;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)case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:if(year % 4 = 0 && year % 100 !=0) return 29;if(year % 100 = 0 && year % 400 !=0)return 29;return 28;default:return 0;(4) 運行結(jié)果圖5-3

注意事項

本文(JAVA基礎(chǔ)實驗編程)為本站會員(jun****875)主動上傳,裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因為網(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!