




已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
復(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)main4.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.length6.如下定義二維數(shù)組操作錯(cuò)誤的是( )。int a=1,2,3;(A)a01=200 (B)a0.length (C)a11=100 (D)a.length7. 以下數(shù)據(jù)類型存儲(chǔ)空間最大的是( B )。(A)byte(B)long(C)float (D)char8. 面向?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. 以下代碼執(zhí)行的結(jié)果是( C )。System.out.println(攀枝花學(xué)院pzhu.length();()編譯錯(cuò)誤()運(yùn)行錯(cuò)誤()9()1413. 用來(lái)存儲(chǔ)鍵值對(duì)的容器是( )。(A)ArrayList(B)LinkedList(C)HashSet (D) HashMap14、java中用來(lái)拋出異常的關(guān)鍵字是( C )。()try ()catch ()throw()throws15.關(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)finally塊中的語(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ù)的操作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ò)誤的是( 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()二、程序閱讀- 8 -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 i1;static 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.println(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() 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();abstract class TA implements ITpublic 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 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ù)量 * 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;icount;i+)int n=(int)(Math.random()*1000);numberi= n ;/在number數(shù)組中寫入生成的隨機(jī)數(shù)System.out.println(number+i+=+numberi);return number ; /返回生成的數(shù)組/* *計(jì)算給定數(shù)組的奇數(shù)的比率 *param int number要計(jì)算的數(shù)組 *return double奇數(shù)的比率 */double calculateOddRate(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ù)為:+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ǔ)全程序的空白處。表:StudentsIDNAMEGENDER2name02女4name04女部分程序如下class Studentprivate int id;private String name;private String gender;public Student(int id, String name, String gender) super();this.id = id; = 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è)記錄生成多個(gè)Student,將生成的對(duì)象放入到List中,一起返回到 */List queryAllStudent()List stuList= new ArrayList() ;/創(chuàng)建可以存儲(chǔ)Student的ListConnection 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(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(List stuList)for(_Student_s:stuList) /指明s的類型System.out.println(s);public static void main(String args) T30 demo=new T30();List stuList=demo.queryAllStudent();demo.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 FileNameParse void showSourceFileName(); 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.out.println(解析文件名:+this.fileName);/請(qǐng)完成此類的中其他方法的代碼/public class T36 public static void main(String args) FileNameParse fp=new WindowsFileNameParse(d:/My Documents/MyJob/Pages/2012-2013-2/PageA/src/T37.java);fp.showSourceFileName();System.out.println(盤符:+fp.getDiskName();System.out.println(文件全名(帶擴(kuò)展名):+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/2012-2013-2/PageA/src/T37.java盤符:d文件全名(帶擴(kuò)展名):T37.java文件名(不帶擴(kuò)展名):T37文件擴(kuò)展名:java路徑(不帶盤符):/My Documents/MyJob/Pages/2012-2013-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 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) return 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 specified 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 string 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 urge smiles.substring(1, 5) returns mile Parameters:beginIndex - 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) l
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 華為公司績(jī)效管理戰(zhàn)略與目標(biāo)分解(9P)
- 2025-2026學(xué)年人教版英語(yǔ)八年級(jí)上冊(cè) 【Unit-7 When Tomorrow Comes】-單詞課件
- 江蘇省鹽城市2025屆高三5月考前指導(dǎo)政治押題卷(含答案)
- 2025年全國(guó)中學(xué)生生物知識(shí)競(jìng)賽題庫(kù)及答案
- 消毒隔離制度試題及答案
- 江蘇省連云港市贛榆初級(jí)中學(xué)2024-2025學(xué)年七年級(jí)下學(xué)期6月月考?xì)v史試題(含答案)
- 杭州學(xué)軍中學(xué)2024學(xué)年第二學(xué)期高三數(shù)學(xué)學(xué)科模擬試卷
- 安徽省六安市獨(dú)山中學(xué)2024-2025學(xué)年高一下學(xué)期5月月考數(shù)學(xué)試卷(含答案)
- 2025年江蘇省徐州市沛縣實(shí)驗(yàn)學(xué)校聯(lián)盟學(xué)區(qū)中考三模地理試題(含答案)
- 化學(xué)●全國(guó)甲卷丨2022年普通高等學(xué)校招生全國(guó)統(tǒng)一考試化學(xué)試卷及答案
- 中醫(yī)診斷學(xué)(浙江中醫(yī)藥大學(xué))知到課后答案智慧樹(shù)章節(jié)測(cè)試答案2025年春浙江中醫(yī)藥大學(xué)
- 現(xiàn)場(chǎng)組焊施工方案
- 教師專業(yè)發(fā)展知到智慧樹(shù)章節(jié)測(cè)試課后答案2024年秋西南大學(xué)
- 齦上潔治術(shù)課件
- 2024年山東省新高考地理試卷(含答案)
- 麻醉期間反流誤吸的預(yù)防與處理
- 西門子S7-1500PLC技術(shù)及應(yīng)用課件:項(xiàng)目資料的打印與歸檔
- 《化學(xué)反應(yīng)原理》課件
- 結(jié)構(gòu)膠灌注施工方案
- 《中醫(yī)體重管理臨床指南》
- 銀行業(yè)務(wù)專家競(jìng)聘述職模板
評(píng)論
0/150
提交評(píng)論