Java程序設(shè)計(jì)試題及答案_第1頁(yè)
Java程序設(shè)計(jì)試題及答案_第2頁(yè)
Java程序設(shè)計(jì)試題及答案_第3頁(yè)
Java程序設(shè)計(jì)試題及答案_第4頁(yè)
Java程序設(shè)計(jì)試題及答案_第5頁(yè)
已閱讀5頁(yè),還剩8頁(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)介

1、JAVA程序設(shè)計(jì)試卷(A卷)得分閱卷人一、選擇題(每小題 2分,共 40 分。)1JDK提供的編譯器是( )。(A)java.exe (B)javac.exe(C)javap.exe (D)javaw.exe2.以下作為Java程序入口的main 方法聲明正確的( )。(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ò)誤的是( )。(A)Publi

2、c(B)張三(C)class (D)main4.java中定義字符串String s=”pzhu”,下面操作可以取得字符串長(zhǎng)度的是( )。(A)s.length() (B)s.length (C)s.size() (D)length(s)5.如下定義數(shù)組,操作正確的是( )。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ǔ)空間最大的是( )。(A)byte(B)l

3、ong(C)float (D)char8. 面向?qū)ο蟮娜筇匦?,不包括如?( )。(A)異常(B)封裝(C)繼承(D)多態(tài)9、關(guān)于類的定義以下說(shuō)法錯(cuò)誤()。(A)類定義使用class關(guān)鍵字 (B)每個(gè)類中必須有一個(gè)main方法(C)一個(gè)包可以包含多個(gè)類 (D)java中所有類都是Object類的子類10. 關(guān)于構(gòu)造方法以下說(shuō)法錯(cuò)誤的是 ( )。()構(gòu)造方法名必須與類名一致 ()構(gòu)造方法可以重載()構(gòu)造方法是通過(guò)new來(lái)調(diào)用 ()每個(gè)類都必須編寫構(gòu)造方法代碼11.關(guān)于繼承如下說(shuō)法錯(cuò)誤的是( )。()Java是單繼承的 ()通過(guò)extends來(lái)定義繼承()所有父類方法都可以被override的

4、()繼承呈現(xiàn)的是is a的關(guān)系12. 以下代碼執(zhí)行的結(jié)果是( )。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)鍵字是( )。()try ()catch ()throw()throws15.關(guān)于finally塊中的代碼,以下說(shuō)法不正確的是( )。(A)try塊中的return語(yǔ)句會(huì)中斷finally塊中語(yǔ)句的執(zhí)行(B)無(wú)論finally塊前的語(yǔ)句運(yùn)行是否產(chǎn)生異常,其

5、中的語(yǔ)句都會(huì)執(zhí)行(C)finally塊中的語(yǔ)句通常中用作資源的清理()try塊中的System.exit(1)語(yǔ)句會(huì)中斷finally塊中語(yǔ)句的執(zhí)行16.關(guān)于Java字符串說(shuō)法錯(cuò)誤的是( )。()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傳

6、遞給數(shù)據(jù)庫(kù)服務(wù)器來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)的操作18.以下程序代碼錯(cuò)誤的是( )。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)建有誤的是( )。()Collection c=new ArrayList();()Collection c=new LinkedList();()Collection c=new HashSet();()Collection c=new Hash

7、Map();20. 以下程序代碼錯(cuò)誤的是( )。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()得分閱卷人二、程序閱讀(每題 5分,共 20分)21.閱讀程序,并寫出程序運(yùn)行結(jié)果public class T21 static int init()System.out.println(A);return 0;static boolean test(in

8、t 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.

9、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);23 閱讀程序,并寫出程序運(yùn)行結(jié)果abstract class PP()System.out.println(P);abstract void goo();class A extend

10、s 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();24 閱讀程序,并寫出程序運(yùn)行結(jié)果interface ITvoid t1(

11、);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);public void t2(int i) System.out.println(E);public class T24 public static void ma

12、in(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);得分閱卷人三、程序填空(每空2分,共 20分)程序一:如下程序測(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要生成

13、的隨機(jī)數(shù)量 * return int 生成的隨機(jī)數(shù)存儲(chǔ)數(shù)組 */int createArray(int count)int number= (25) ; /創(chuàng)建長(zhǎng)度為count的int數(shù)組for(int i=0;icount;i+)int n=(int)(Math.random()*1000);numberi= (26) ;/在number數(shù)組中寫入生成的隨機(jī)數(shù)System.out.println(number+i+=+numberi);return (27) ; /返回生成的數(shù)組/* *計(jì)算給定數(shù)組的奇數(shù)的比率 *param int number要計(jì)算的數(shù)組 *return double奇數(shù)

14、的比率 */double calculateOddRate(int number)int count=(28) ; /讀取數(shù)組元素的個(gè)數(shù),即要計(jì)算平均數(shù)的整數(shù)個(gè)數(shù)double odd=0;/奇數(shù)計(jì)數(shù)for(int n:number)if( (29) )/如果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.pri

15、ntln(奇數(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 S

16、tudent(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ì)象,

17、 * 多個(gè)記錄生成多個(gè)Student,將生成的對(duì)象放入到List中,一起返回到 */List queryAllStudent()List stuList= (30) ;/創(chuàng)建可以存儲(chǔ)Student的ListConnection conn=null;Statement st=null;ResultSet rs=null;try conn=getConnection();st= (31) .createStatement(); /通過(guò)連接創(chuàng)建statementrs=st.executeQuery(SELECT ID,NAME,GENDER FROM Students);while( (32) )

18、/結(jié)果是否有記錄Student stu=new Student(rs.getInt(ID),rs.getString(NAME),rs.getString(GENDER); (33) ; /把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(_(34)_s:st

19、uList) /指明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=女得分閱卷人四、基本代碼編寫(共12分)35、(5分)編寫一個(gè)main方法,計(jì)算如下數(shù)組元素的平均值 double source=2,5,9,10

20、,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 fil

21、eName;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

22、/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/2

23、012-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) retu

24、rn 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

25、 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 beginInde

26、x)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,

27、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-be

28、ginIndex. 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ì)并編程(共8分)37、仔細(xì)閱讀給定的代碼和程序運(yùn)行結(jié)果,完方法size()、del()代碼編寫。MyList類是可以存儲(chǔ)字符串對(duì)象的、基于鏈

29、表的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; els

30、e MyListNode lastNode = firstNode;while (lastNode.nextNode != null) lastNode = lastNode.nextNode;lastNode.nextNode = node;public int size() /返回MyList中節(jié)點(diǎn)數(shù)/完成此方法代碼/public String toArray() /將MyList中存儲(chǔ)的所有字符串轉(zhuǎn)化成Stringint count = size();if (count = 0) return null;String dest = new Stringcount;MyListNode l

31、astNode = firstNode;int i = 0;do desti+ = lastNode.element;lastNode = lastNode.nextNode; while (lastNode != null);return dest;public void del(String element) /刪除節(jié)點(diǎn)元素值為element字符串的節(jié)點(diǎn)/完成此方法代碼/public class T37 public static void main(String args) MyList myList = new MyList();myList.add(s001);myList.add(

32、s002);myList.add(s003);myList.add(s004);myList.add(s005);System.out.println(SIZE: + myList.size();String sa1 = myList.toArray();showArray(sa1);myList.del(s001);myList.del(s003);myList.del(s005);System.out.println(SIZE: + myList.size();String sa2 = myList.toArray();showArray(sa2);static void showArra

33、y(String sa) System.out.print();for (String s : sa) System.out.print(s + );System.out.println();運(yùn)行結(jié)果SIZE:5 s001 s002 s003 s004 s005 SIZE:2s002 s004 Java程序設(shè)計(jì)試卷(A卷) 評(píng)閱標(biāo)準(zhǔn)及考核說(shuō)明得分閱卷人一、教師答題時(shí)間: 15 分鐘 選擇題(每小題 2 分,共 40 分。請(qǐng)將答案填在下面的表格內(nèi))1、三基類B 2、三基類 C 3、三基類C 4、三基類A5、三基類D6、三基類C 7、三基類B 8、三基類A9、三基類10、三基類11、三基類C12、

34、三基類C13、三基類D14、三基類15、三基類16、三基類17、三基類18、三基類19、三基類20、三基類得分閱卷人二、教師答題時(shí)間: 10 分鐘 填空題(每小題5分,共 20 分)21、三基類 ABDCB22、三基類 AEDCB23、三基類 PAFPK24、三基類 CDCBE得分閱卷人三、教師答題時(shí)間: 10 分鐘 程序填空(每空2分,共 20分)25、一般綜合型 new intcount26、一般綜合型 n27、一般綜合型 number28、一般綜合型 number.length29、一般綜合型 n%2=130、一般綜合型 new ArrayList()或new LinkedList()3

35、1、一般綜合型 conn32、一般綜合型 rs.next()33、一般綜合型 stuList.add(stu)34、一般綜合型 Student得分閱卷人四、基本代碼編寫(共12分)35、(5分)一般綜合型教師答題時(shí)間: 2 分鐘 參考程序public static void main(String args) int source=2,5,9,10,3;double sum=0;int count=source.length;for(int i=0;icount;i+)sum+=sourcei;System.out.println(sum/count);評(píng)分說(shuō)明:(1)評(píng)分總體原則以實(shí)現(xiàn)功能為最終標(biāo)準(zhǔn),無(wú)論用什么方式實(shí)現(xiàn)只要程序?qū)崿F(xiàn)了題目要求的功能的情況,沒(méi)有語(yǔ)法錯(cuò)誤(個(gè)別筆誤除外)的情況下可得到滿分(2)沒(méi)有實(shí)現(xiàn)題目要求功能的情況,如下步驟可以得分a.正確寫出main方法得分b.寫出數(shù)組的初始化的情況下可以得1分b.寫出for循環(huán)正確得分c.格式基本正確得1分36、(7分)綜合型教師答題時(shí)間: 3 分鐘 參考程序public String getDiskName()(分)return fi

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論