版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、java模擬試卷3及答案復(fù)習(xí)題3一、選擇題1JDK提供的編譯器是(B)。(A)java.exe (B)javac.exe(C)javap.exe (D)javaw.exe2.以下作為Java程序入口的main 方法聲明正確的(C)。(A)public void main(String args)(B)public int main(String args)(C)public static void main(String args)(D)public static int main(String args)3.以下標(biāo)識(shí)符錯(cuò)誤的是(C)。(A)Public (B)張三(C)class (D)ma
2、in4.java中定義字符串String s=”pzhu”,下面操作可以取得字符串長(zhǎng)度的是(A)。(A)s.length() (B)s.length (C)s.size() (D)length(s)5.如下定義數(shù)組,操作正確的是(D)。int a=1,2,3;(A)a3=100 (B)a0.length (C)a+ (D)a.length 6.如下定義二維數(shù)組操作錯(cuò)誤的是()。int a=1,2,3;(A)a01=200 (B)a0.length (C)a11=100 (D)a.length 7. 以下數(shù)據(jù)類型存儲(chǔ)空間最大的是( B )。(A)byte (B)long(C)float (D)c
3、har8. 面向?qū)ο蟮娜筇匦裕话ㄈ缦? A)。(A)異常(B)封裝(C)繼承(D)多態(tài)9、關(guān)于類的定義以下說(shuō)法錯(cuò)誤(B)。(A)類定義使用class關(guān)鍵字(B)每個(gè)類中必須有一個(gè)main方法(C)一個(gè)包可以包含多個(gè)類(D)java中所有類都是Object類的子類10. 關(guān)于構(gòu)造方法以下說(shuō)法錯(cuò)誤的是( D)。()構(gòu)造方法名必須與類名一致()構(gòu)造方法可以重載()構(gòu)造方法是通過(guò)new來(lái)調(diào)用()每個(gè)類都必須編寫構(gòu)造方法代碼11.關(guān)于繼承如下說(shuō)法錯(cuò)誤的是(C)。()Java是單繼承的()通過(guò)extends來(lái)定義繼承()所有父類方法都可以被override的()繼承呈現(xiàn)的是is a的關(guān)系12. 以下
4、代碼執(zhí)行的結(jié)果是( C)。System.out.println(攀枝花學(xué)院pzhu.length();()編譯錯(cuò)誤()運(yùn)行錯(cuò)誤()9 ()14 13. 用來(lái)存儲(chǔ)鍵值對(duì)的容器是( )。(A)ArrayList (B)LinkedList (C)HashSet (D)HashMap 14、java中用來(lái)拋出異常的關(guān)鍵字是(C)。()try ()catch ()throw ()throws 15.關(guān)于finally塊中的代碼,以下說(shuō)法不正確的是(A)。(A)try塊中的return語(yǔ)句會(huì)中斷finally塊中語(yǔ)句的執(zhí)行(B)無(wú)論finally塊前的語(yǔ)句運(yùn)行是否產(chǎn)生異常,其中的語(yǔ)句都會(huì)執(zhí)行(C)fin
5、ally塊中的語(yǔ)句通常中用作資源的清理()try塊中的System.exit(1)語(yǔ)句會(huì)中斷finally塊中語(yǔ)句的執(zhí)行16.關(guān)于Java字符串說(shuō)法錯(cuò)誤的是( B)。()Java中的字符串是常量()Java中的字符串不是對(duì)象()Java中的字符串存儲(chǔ)在常量池中()一個(gè)字符串定義后的長(zhǎng)度不可變17.關(guān)于JDBC操作數(shù)據(jù)庫(kù),以下說(shuō)法不正確的()。()JDBC只能操作MySQL數(shù)據(jù)庫(kù)()JDBC中定義的Connection,Statement,ResultSet都是接口()JDBC操作數(shù)據(jù)庫(kù)必須要有相應(yīng)的實(shí)現(xiàn)了JDBC接口的驅(qū)動(dòng)()JDBC可以通過(guò)將客戶端的SQL傳遞給數(shù)據(jù)庫(kù)服務(wù)器來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)的操作
6、18.以下程序代碼錯(cuò)誤的是(B)。abstract class Pclass A extends Pabstract class B extends P()P p=new A();()P p=new B();()A a=new A();()P p=new P()void foo();19.以下ollection c創(chuàng)建有誤的是(D)。()Collection c=new ArrayList();()Collection c=new LinkedList();()Collection c=new HashSet();()Collection c=new HashMap();20. 以下程序代碼錯(cuò)
7、誤的是(C)。interface IAvoid f();()abstract class A implements IA ()class A implements IAvoid f()()class A implements IAvoid f(String s) ()IA a=new IA()void f()二、程序閱讀21.閱讀程序,并寫出程序運(yùn)行結(jié)果public class T21 static int init()System.out.println(A);return 0;static boolean test(int i)System.out.println(B);return is
8、tatic int add(int i)System.out.println(C);return +i;public static void main(String args) for(int t=init();test(t);t=add(t)System.out.println(D); 22.閱讀程序,并寫出程序運(yùn)行結(jié)果class TObjectTObject()System.out.println(A);void m(String s)System.out.println(B);void m(int i)System.out.println(C);void m()System.out.pr
9、intln(D);public String toString()return E;public class T22 public static void main(String args) TObject obj=new TObject();System.out.println(obj);obj.m();obj.m(1);obj.m(1);答:輸出結(jié)果為:D C B23 閱讀程序,并寫出程序運(yùn)行結(jié)果abstract class PP()System.out.println(P);abstract void goo();class A extends PA()super();void goo(
10、) System.out.println(A);void foo()System.out.println(F);class B extends Pvoid goo() System.out.println(B);void koo()System.out.println(K);public class T23 public static void main(String args) A a=new A();a.goo();a.foo();B b=new B();b.koo();答:P A F P K24 閱讀程序,并寫出程序運(yùn)行結(jié)果interface ITvoid t1();void t2();
11、abstract class TA implements IT public void t1() System.out.println(A);public void t3() System.out.println(B);class TB extends TApublic void t1() System.out.println(C);public void t2() System.out.println(D); 答:B C D C B Epublic void t2(int i) System.out.println(E);public class T24 public static void
12、 main(String args) IT obj=new TB();obj.t1();obj.t2();TA aObj=(TA)obj;aObj.t1();aObj.t3();TB bObj=(TB)obj;bObj.t2(100);答:A E D C A B三、程序填空程序一:如下程序測(cè)試Math.random生成隨機(jī)數(shù)的奇偶比率,仔細(xì)閱讀程序和運(yùn)行結(jié)果,補(bǔ)全空白處的代碼。/* 測(cè)試Math.random生成隨機(jī)數(shù)的奇偶比率*/public class T25 /* 生成給定數(shù)量的到1000隨機(jī)整數(shù),并把生成的隨機(jī)存入到一個(gè)int數(shù)組中* param int count要生成的隨機(jī)數(shù)量*
13、return int 生成的隨機(jī)數(shù)存儲(chǔ)數(shù)組*/int createArray(int count)int number= new intcount; /創(chuàng)建長(zhǎng)度為count的int數(shù)組for(int i=0;iint n=(int)(Math.random()*1000);numberi= n;/在number數(shù)組中寫入生成的隨機(jī)數(shù)System.out.println(number+i+=+numberi);return numbe r ; /返回生成的數(shù)組/*計(jì)算給定數(shù)組的奇數(shù)的比率*param int number要計(jì)算的數(shù)組*return double 奇數(shù)的比率*/double cal
14、culateOddRate(int number)int count=number.length; /讀取數(shù)組元素的個(gè)數(shù),即要計(jì)算平均數(shù)的整數(shù)個(gè)數(shù)double odd=0;/奇數(shù)計(jì)數(shù)for(int n:number)if( n%2=1)/如果n是奇數(shù),奇數(shù)計(jì)數(shù)加odd+;return odd/count;public static void main(String args) T25 t=new T25();int number=t.createArray(100);double oddRate=t.calculateOddRate(number);System.out.println(奇數(shù)為
15、:+oddRate*100+%);System.out.println(偶數(shù)為:+(1-oddRate)*100+%);運(yùn)行結(jié)果:number0=907./此處省略98行number99=598奇數(shù)為:52.0%偶數(shù)為:48.0%程序二:以下程序是通過(guò)JDBC讀取數(shù)據(jù)表Student的基本操作,認(rèn)真閱讀程序和運(yùn)行結(jié)果,補(bǔ)全程序的空白處。class Studentprivate int id;private String name;private String gender;public Student(int id, String name, String gender) super();th
16、is.id = id;/doc/d5e1535f195f312b3069a582.html = name;this.gender = gender;/此處省略n行public String toString() return Student id= + id + , name= + name + , gender= + gender+ ;public class T30 /*取得數(shù)據(jù)庫(kù)連接*/Connection getConnection()/此處省略n行/* 查詢數(shù)據(jù)庫(kù)中所有學(xué)生的數(shù)據(jù),將一條學(xué)生信息記錄轉(zhuǎn)化成一個(gè)Studetn對(duì)象,* 多個(gè)記
17、錄生成多個(gè)Student,將生成的對(duì)象放入到List中,一起返回到*/ListListConnection conn=null;Statement st=null;ResultSet rs=null;try conn=getConnection();st= conn.createStatement(); /通過(guò)連接創(chuàng)建statementrs=st.executeQuery(SELECT ID,NAME,GENDER FROM Students);while( rs.next() /結(jié)果是否有記錄Student stu=new Student(rs.getInt(ID),rs.getString
18、(NAME),rs.getString(GENDER);stuList.add(stu); /把stu對(duì)象加入到stuList中 catch (SQLException e) e.printStackTrace();finallytry rs.close();st.close();conn.close(); catch (SQLException e) return stuList;/*顯示List中的學(xué)生*/void showStudent(Listfor(_Student_s:stuList) /指明s的類型System.out.println(s);public static void
19、main(String args) T30 demo=new T30();Listdemo.showStudent(stuList);運(yùn)行結(jié)果Student id=2, name=Name02, gender=女Student id=4, name=Name04, gender=女四、基本代碼編寫35、(5分)編寫一個(gè)main方法,計(jì)算如下數(shù)組元素的平均值double source=2,5,9,10,3;36、(分)文件名解析器,仔細(xì)閱讀如下代碼和運(yùn)行結(jié)果,完成WindowsFileNameParse類的代碼,執(zhí)行后得到給定的運(yùn)行結(jié)果。interface FileNameParsevoid s
20、howSourceFileName();String getDiskName();String getFullFileName();String getFileName();String getExtendName();String getDir();class WindowsFileNameParse implements FileNameParseprivate String fileName;WindowsFileNameParse(String fileName)this.fileName=fileName;public void showSourceFileName()System.
21、out.println(解析文件名:+this.fileName);/請(qǐng)完成此類的中其他方法的代碼/public class T36 public static void main(String args) FileNameParse fp=new W indowsFileNameParse(d:/MyDocuments/MyJob/Pages/2021-2021-2/PageA/src/T37.java);fp.showSourceFileName();System.out.println(盤符:+fp.getDiskName();System.out.println(文件全名(帶擴(kuò)展名):
22、+fp.getFullFileName();System.out.println(文件名(不帶擴(kuò)展名):+fp.getFileName();System.out.println(文件擴(kuò)展名:+fp.getExtendName();System.out.println(路徑(不帶盤符):+fp.getDir();運(yùn)行結(jié)果解析文件名:d:/My Documents/MyJob/Pages/2021-2021-2/PageA/src/T37.java盤符:d文件全名(帶擴(kuò)展名):T37.java文件名(不帶擴(kuò)展名):T37文件擴(kuò)展名:java路徑(不帶盤符):/My Documents/MyJob/
23、Pages/2021-2021-2/PageA/src附String類部分的api docpublic int indexOf(String str)Returns the index within this string of the first occurrence of the specified substring.Examples: abca.indexOf(a) return 0Parameters:str - the substring to search for.Returns:the index of the first occurrence of the specified
24、 substring, or -1 if there is no such occurrence.public int lastIndexOf(String str)Returns the index within this string of the last occurrence of the specified substring. The last occurrence of the empty string is considered to occur at the index value this.length().Examples: abca.lastIndexOf(a) ret
25、urn 3Parameters:str - the substring to search for.Returns:the index of the last occurrence of the specified substring, or -1 if there is no such occurrence.public String substring(int beginIndex)Returns a new string that is a substring of this string. The substring begins with the character at the s
26、pecified index and extends to the end of this string.Examples:Harbison.substring(3) returns bisonemptiness.substring(9) returns (an empty string)Parameters:beginIndex - the beginning index, inclusive.Returns:the specified substring.public String substring(int beginIndex, int endIndex)Returns a new s
27、tring that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.Examples:hamburger.substring(4, 8) returns urgesmiles.substring(1, 5) returns mileParameters:beginInd
28、ex - the beginning index, inclusive.endIndex - the ending index, exclusive.Returns:the specified substring.五、設(shè)計(jì)并編程37、仔細(xì)閱讀給定的代碼和程序運(yùn)行結(jié)果,完方法size()、del()代碼編寫。MyList類是可以存儲(chǔ)字符串對(duì)象的、基于鏈表的List的簡(jiǎn)單實(shí)現(xiàn)class MyListNode String element;MyListNode nextNode = null;MyListNode(String element) this.element = element;class MyList private MyListNode firstNode = null;public void add(String element) /加入字符串到MyList中MyListNode node = new MyListNode(element);if (firstNode = null) firstNode = node; else MyListNode lastNode = firstNode;while (lastNode.nextNode != null) lastNode = lastNode
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度環(huán)??萍脊狙邪l(fā)人員勞動(dòng)合同范本
- 2025年度物流園區(qū)合同法運(yùn)輸管理服務(wù)協(xié)議
- 2025年度節(jié)能改造項(xiàng)目工程監(jiān)理服務(wù)合同書
- 2025年度家電行業(yè)供應(yīng)鏈金融服務(wù)合同
- 2025年度綠色環(huán)保技術(shù)擔(dān)保付款合同
- 2025年度建筑企業(yè)應(yīng)收賬款融資合同樣本
- 2025年度磚廠磚瓦產(chǎn)品銷售與市場(chǎng)分析合作合同
- 2025年度航空航天專利技術(shù)合作合同
- 2025年度環(huán)保咨詢服務(wù)竣工環(huán)境保護(hù)驗(yàn)收合同范本模板
- 2025年度新材料研發(fā)股權(quán)合資與市場(chǎng)推廣合同
- 2024年江西省南昌市南昌縣中考一模數(shù)學(xué)試題(含解析)
- 繪本的分鏡設(shè)計(jì)-分鏡的編排
- 查干淖爾一號(hào)井環(huán)評(píng)
- 體檢中心分析報(bào)告
- 人教版初中英語(yǔ)七八九全部單詞(打印版)
- 臺(tái)球運(yùn)動(dòng)中的理論力學(xué)
- 最高人民法院婚姻法司法解釋(二)的理解與適用
- 關(guān)于醫(yī)保應(yīng)急預(yù)案
- 新人教版五年級(jí)上冊(cè)數(shù)學(xué)應(yīng)用題大全doc
- 2022年版義務(wù)教育勞動(dòng)課程標(biāo)準(zhǔn)學(xué)習(xí)培訓(xùn)解讀課件筆記
- 2022年中國(guó)止血材料行業(yè)概覽:發(fā)展現(xiàn)狀對(duì)比分析研究報(bào)告(摘要版) -頭豹
評(píng)論
0/150
提交評(píng)論