java數(shù)組與異常處理復(fù)習(xí)題.doc_第1頁
java數(shù)組與異常處理復(fù)習(xí)題.doc_第2頁
java數(shù)組與異常處理復(fù)習(xí)題.doc_第3頁
java數(shù)組與異常處理復(fù)習(xí)題.doc_第4頁
java數(shù)組與異常處理復(fù)習(xí)題.doc_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

第五、六章習(xí)題一、選擇題1下列關(guān)于數(shù)組的定義形式,哪些是錯誤的?( ABC )Aint c=new char10; Bint 3=new int2 ;Cint a; a=new int; Dchar b ; b=new char80; 2執(zhí)行String s=new String10;語句后,哪些結(jié)論是正確的?( BC )As0 為 未定義 Bs.length 為10Cs9 為 null Ds10 為 3下列關(guān)于Java語言的數(shù)組描述中,錯誤的是( D )。A數(shù)組的長度通常用length表示 B數(shù)組下標(biāo)從0開始 C數(shù)組元素是按順序存放在內(nèi)存的 D數(shù)組在賦初值和賦值時都不判界4下面的表達(dá)式哪些是正確的? ( ACE )AString s=你好;int i=3; s+=i; BString s=你好;int i=3; if(i=s) s+=i; CString s=你好;int i=3; s=i+s; DString s=你好;int i=3; s=i+; E. String s=null; int i=(s!=null)&(s.length()0)?s.length():0;5public class T18 static int arr = new int10;public static void main(String a) System.out.println(arr1);哪個語句是正確的?( C )A編譯時將產(chǎn)生錯誤 B編譯時正確,運行時將產(chǎn)生錯誤C輸出零 D輸出空6若String s = hello; String t = hello; char c = h,e,l,l,o ; 則下列哪些表達(dá)式返回true?( AB )7指出正確的表達(dá)式有( AB )。Adouble a=2.0; BDouble a=new Double(2.0);Cbyte A= 350; DByte a = 120;8System類在哪個包中?( B )Ajava.awt Bjava.lang Cjava.util Djava.io9關(guān)于Float,下列說法正確的是( ACD )。AFloat在java.lang包中 BFloat a=1.0是正確的賦值方法CFloat是一個類 DFloat a= new Float(1.0)是正確的賦值方法10.ava中用來拋出異常的關(guān)鍵字是AA.tryB.catchC.throwD.finally11.關(guān)于異常,下列說法正確的是AA.異常是一種對象B.一旦程序運行,異常將被創(chuàng)建C.為了保證程序運行速度,要盡量避免異??刂艱.以上說法都不對12.(C)類是所有異常類的父類。A.ThrowableB.ErrorC.ExceptionD.AWTError13.java語言中,下列哪一子句是異常處理的出口AA.try子句B.catch子句C.finally子句D.以上說法都不對14.下列程序的執(zhí)行,說法正確的是Dclass MultiCatch public static void main(String args) try int a=args.length; int b=42/a; int c=1; c42=99; System.out.println(“b=”+b); catch(ArithmeticException e) System.out.println(“除0異常:”+e); catch(ArrayIndexOutOfBoundsException e) System.out.println(“數(shù)組超越邊界異常:”+e); A.程序?qū)⑤敵龅?5行的異常信息B.程序第10行出錯C.程序?qū)⑤敵觥癰=42”D.程序?qū)⑤敵龅?9行的異常信息15.下列程序的執(zhí)行,說法正確的是Dclass ExMulti static void procedure() try int c=1; c42=99; catch(ArrayIndexOutOfBoundsException e) System.out.println(“數(shù)組超越界限異常:”+e); public static void main(String args) try procedure(); int a=args.length; int b=42/a; System.out.println(“b=”+b); catch(ArithmeticException e) System.out.println(“除0異常:”+e); A.程序只輸出第12行的異常信息B.程序只輸出第26行的異常信息C.程序?qū)⒉惠敵霎惓P畔.程序?qū)⑤敵龅?2行和第26行的異常信息16.下面程序拋出了一個“異?!辈⒉蹲剿U堅跈M線處填入適當(dāng)內(nèi)容完成程序。class TrowsDemo static void procedure() throws IllegalAccessExcepton System.out.println(“inside procedure”); throw_new_IllegalAccessException(“demo”); public static void main(String args) try procedure(); _catch(IllegalAccessException e) System.out.println(“捕獲:”+e); 二、填空題1.catch子句都帶一個參數(shù),該參數(shù)是某個異常的類及其變量名,catch用該參數(shù)去與_拋出異常_對象的類進(jìn)行匹配。2.java虛擬機(jī)能自動處理_運行_異常。3.變量屬性是描述變量的作用域,按作用域分類,變量有局部變量、類變量、方法參數(shù)和_異常處理參數(shù)_同一段程序可能產(chǎn)生不止一種異常。可以放置多個_子句,其中每一種異常類型都將被檢查,第一個與之匹配的就會被執(zhí)行。4.捕獲異常要求在程序的方法中預(yù)先聲明,在調(diào)用方法時用try-catch-_finally_語句捕獲并處理。5.java語言認(rèn)為那些可預(yù)料和不可預(yù)料的出錯稱為_異常_6.按異常處理不同可以分為運行異常、捕獲異常、聲明異常和_拋出異常_幾種。7.拋出異常的程序代碼可以是_java應(yīng)用程序_或者是JDK中的某個類,還可以是JVN.8.拋出異常、生成異常對象都可以通過_throw_語句實現(xiàn)。9.捕獲異常的統(tǒng)一出口通過_finally_語句實現(xiàn)。10.java語言的類庫中提供了一個_Throwable_類,所有的異常都必須是它的實例或它子類的實例。11.Throwable類有兩個子類:_Error_類和Exception類。12.對程序語言而言,一般有編譯錯誤和_運行_錯誤兩類。13.下面程序定義了一個字符串?dāng)?shù)組,并打印輸出,捕獲數(shù)組超越界限異常。請在橫線處填入適當(dāng)?shù)膬?nèi)容完成程序。public class HelloWorld int i=0; String greetings= “Hello world!”, “No,I mean it!”, “HELLO WORLD!” ; while(i4) _try_System.out.println(greetingi);_catch_(ArrayIndexOutOfBoundsException e)System.out.println(“Re-setting Index Value”);i=-1;finally System.out.println(“This is always printed”); i+;三、判斷題1String str=abcdefghi;char chr=str.charAt(9); ( )2char chrArray= a, b, c, d, e, f, g;char chr=chrArray6; ( )3int i,j;boolean booleanValue=(i=j); ( )4int intArray=0,2,4,6,8; int length=int Array.length();( )5String str=abcedf; int length=str.length; ( )6int intArray60; ( )7char str=abcdefgh; ( )8說明或聲明數(shù)組時不分配內(nèi)存大小,創(chuàng)建數(shù)組時分配內(nèi)存大小。( )9Integer i = (Integer.valueOf(926).intValue();( )10String s = (Double.valueOf(3.1415926).toString(); ( )11Integer I = Integer.parseInt(926);( )12Arrays類主要對數(shù)組進(jìn)行操作。( )四、程序分析題1分析下面的程序,寫出運行結(jié)果。public class Exercises5_1 String str = new String(Hi !);char ch = L, i, k, e ;public static void main(String args) Exercises5_1 ex = new Exercises5_1();ex.change(ex.str, ex.ch);System.out.print(ex.str + );System.out.print(ex.ch);public void change(String str, char ch) str = How are you;ch1 = u;運行結(jié)果是:( Hi ! Luke )2. 分析下面的程序,寫出運行結(jié)果:public class Exercises5_3 public static void main(String args) String str1 = new String();String str2 = new String(String 2);char chars = a, , s, t, r, i, n, g ;String str3 = new String(chars);String str4 = new String(chars, 2, 6);byte bytes = 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,0x39 ;String str5 = new String(bytes);StringBuffer strb = new StringBuffer(str3);System.out.println(The String str1 is + str1);System.out.println(The String str2 is + str2);System.out.println(The String str3 is + str3);System.out.println(The String str4 is + str4);System.out.println(The String str5 is + str5);System.out.println(The String strb is + strb); 運行結(jié)果是:( )The String str1 isThe String str2 is String 2The String str3 is a stringThe String str4 is stringThe String str5 is 0123456789The String strb is a string五、改錯題1找出下面代碼的錯誤部分,說明錯誤類型及原因,并更正。public int m1 (in

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論