




已閱讀5頁,還剩14頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
JAVA程序設(shè)計(jì)復(fù)習(xí)題之(三)閱讀程序題(通信工程專業(yè)使用)三、閱讀程序題。1、閱讀以下程序:public class Sum public static void main( String args) double sum = 0.0 ; for ( int i = 1; i= 100; i + ) sum += i;, System.out.println( sum= + sum ); 該程序完成的功能是: 求sum=1+2+3+.+100的和。2、閱讀以下程序:public class Sum public static void main(String args) double sum = 0.0:for (int i=1; i=100; i+)sum += i*i;System.out.println( sum=+sum); 該程序的功能是: 求出sum的值為1到100的平方和。3、閱讀以下程序:public class Sum public static void main(String args) double sum = 0.0;for(int i = 1; i = 100; i+)sum += i*i*i;System.out.println(sum= + sum); 此程序完成的功能是: 計(jì)算并輸出1到100的立方和sum值。4、閱讀以下程序:public class Sum public static void main(String args) double sum = 0.0;for (int i=1; i=100; i+) sum += 1.0 / (double)i;System.out.println(sum=+sum); 此程序完成的功能是: 求解sum=1+1/2+1/3+.+1/100的值并打印輸出。5、閱讀以下程序import java.io.* ;public class Test public static void main(String args ) int i, s = 0;int a = 10, 20, 30, 40, 50, 60, 70, 80, 90;for ( i = 0 ; i a.length; i+ )if(ai % 3 = 0) s += ai;System.out.println(s= + s);請(qǐng)寫出此程序的輸出結(jié)果: s=1806、閱讀以下程序 import java.io.*;public class abc public static void main(String args ) AB s = new AB(Great!,I love Eclipse.); System.out.println(s.toString( ); class AB String s1; String s2; public AB(String str1, String str2) s1 = str1; s2 = str2; public String toString( ) return s1 + s2;運(yùn)行結(jié)果是: 運(yùn)行結(jié)果是:Great! I love Eclipse.7、閱讀以下程序import java.io.* ; public class abc public static void main(String args ) int i, s = 0 ; int a = 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ; for ( i = 0 ; i a.length ; i + ) if ( ai%3 = = 0 ) s += ai ; System.out.println(s=+s); 運(yùn)行結(jié)果是: 運(yùn)行結(jié)果:s = 1808、閱讀以下程序import java.io.* ; public class abc public static void main(String args ) System.out.println(a= + a + nb= + b); class SubClass extends SuperClass int c; SubClass(int aa, int bb, int cc) super(aa, bb); c = cc; class SubSubClass extends SubClass int a; SubSubClass(int aa, int bb, int cc) super(aa, bb, cc); A = aa + bb + cc; void show( )System.out.println(a=+a+nb=+b+nc=+c); 運(yùn)行結(jié)果是: 運(yùn)行結(jié)果:a=60b=20c=309、以下程序的輸出結(jié)果為 相等 。class StringTest1 public static void main(String args) String s1=hello;String s2=new String(hello);if( s1.equals(s2) ) System.out.println(相等);else System.out.println(不相等);10、以下程序段的輸出結(jié)果為 5 6 7 8 9 。public class TestArray public static void main(String args ) int i , j ;int a = 5,9,6,8,7; for ( i = 0 ; i a.length-1; i + ) int k = i; for ( j = i ; j a.length; j+ ) if ( aj ak ) k = j; int temp = ai; ai = ak; ak = temp; for ( i =0 ; ia.length; i+ ) System.out.print(ai+ ); System.out.println( ); 11、寫出以下程序的功能。import java.io.*;public class TestFile public static void main(String args) throws Exception BufferedReader br = new BufferedReader(new InputStreamReader(System.in); BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt); String s; while (true) System.out.print(請(qǐng)輸入一個(gè)字符串: ); System.out.flush( ); s = br.readLine( ); if (s.length() = 0) break; bw.write(s); bw.newLine(); bw.close( ); 程序功能是: 程序功能是:從鍵盤逐一輸入字符串,逐一輸出至input.txt文件中,直至輸入空行。12、閱讀以下程序,寫出輸出結(jié)果。class Animal Animal( ) System.out.print (Animal ); public class Dog extends Animal Dog( ) System.out.print (Dog ); public static void main(String args) Dog snoppy = new Dog(); 輸出結(jié)果是: 輸出結(jié)果是:Animal Dog13、以下程序的輸出結(jié)果為 Peter is 17 years old! 。public class Person String name;int age;public Person(String name, int age) = name;this.age = age;public static void main(String args) Person c = new Person(Peter, 17);System.out.println( + is + c.age + years old!);14、以下程序的輸出結(jié)果為_ 課程號(hào):101 課程名:JSP 學(xué)分:3 _。public class Course private String cNumber;private String cName;private int cUnit;public Course(String number, String name, int unit) cNumber = number;cName = name;cUnit = unit;public void printCourseInfo() System.out.println(課程號(hào): + cNumber + 課程名: + cName + 學(xué)分: + cUnit);class CourseTest public static void main(String args) Course c;c = new Course(101, JSP, 3);c.printCourseInfo();15、以下程序的輸出結(jié)果為_ 湯姆貓?bào)w重:20.0斤 _。public class Tom private float weight;private static String name;public void setWeight(float weight) this.weight = weight;private void out() System.out.println(name + 體重: + weight + 斤);public static void main(String args) T = 湯姆貓;Tom cat = new Tom();cat.setWeight(20);cat.out();16、以下程序的輸出結(jié)果是 _姓名:Tom 年齡:15 家庭住址:宿城區(qū) 電話:66123456 學(xué)校:宿中_。public class Father String name, address, tel;int age;public Father(String name, int age) = name;this.age = age;void out() System.out.print(姓名: + name);System.out.print( 年齡: + age);void outOther() System.out.print( 家庭住址: + address);System.out.print( 電話: + tel);class Son extends Father String school;public Son(String name, int age) super(name, age);void out() super.out();super.outOther();System.out.println( 學(xué)校: + school);public static void main(String args) Son son = new Son(Tom, 15);son.address = 宿城區(qū);son.school = 宿中;son.tel = 66123456;son.out();17、下列程序的運(yùn)行結(jié)果是_ 12345_。public class MyClass int a = 1, 2, 3, 4, 5 ;void out() for (int j = 0; j a.length; j+)System.out.print(aj + );public static void main(String args) MyClass my = new MyClass();my.out();18、閱讀下面的程序,回答問題。import java.awt.*; import javax.swing.*; public class T extends JFrame public T ( ) super(GridLayout); Container con=this.getContentPane(); con.setLayout(new GridLayout(2,3); con.add(new JButton(a); con.add(new JButton(b); con.add(new JButton(c); con.add(new JButton(d); con.add(new JButton(e); con.add(new JButton(f); setSize(200, 80); setVisible(true); public static void main(String args) new T(); 畫圖表示程序運(yùn)行后的圖形界面。如果程序通過實(shí)現(xiàn)某個(gè)接口處理按鈕的動(dòng)作事件,則該接口名為何?接口中的方法頭聲明如何?答案:接口名:ActionListener 接口中的方法:public void actionPerformed(ActionEvent e)19、閱讀下面的程序,并回答問題。import java.io.*;public class Test public static void main(String args) throws IOException BufferedReader buf=new BufferedReader( new InputStreamReader(System.in); while (true) String str = buf.readLine( ); if( str.equals(quit) ) break; int x = Integer.parseInt(str); System.out.println(x*x); 編譯運(yùn)行上面的程序:從鍵盤輸入5,回車后輸出的結(jié)果如何?從鍵盤輸入quit,回車后程序執(zhí)行情況如何?答案:25 終止應(yīng)用程序的運(yùn)行。20、閱讀下面的程序代碼,并回答問題。String s1 = new String(abcde);String s2 = new String(abcde); boolean b1= s1.equals(s2);boolean b2 = s1= s2; System.out.print(b1+ +b2); 程序段執(zhí)行后,在命令行的輸出結(jié)果如何?解釋輸出(1)的結(jié)果的原因?答案: true falseequals方法比較兩個(gè)字符串的內(nèi)容是否相等;運(yùn)算符“=”判斷兩個(gè)對(duì)象是否指向同一個(gè)引用,即是否為同一個(gè)對(duì)象。21、閱讀下面的程序,并回答問題。import java.io.*;public class Test public static void main(String args) throws IOException BufferedReader buf=new BufferedReader( new InputStreamReader(System.in); while (true) String str = buf.readLine(); if( str.equals(quit) ) break; int x = Integer.parseInt(str); System.out.println(x*x); 編譯運(yùn)行上面的程序:從鍵盤輸入10,回車后輸出的結(jié)果如何?從鍵盤輸入exit,回車后程序能正確執(zhí)行嗎?為什么?答案:100 不能;因?yàn)榉椒↖nteger.parseInt(str)不能將字符串“exit”轉(zhuǎn)化為整數(shù),拋出異常。22、寫出下面的程序編譯、運(yùn)行后的結(jié)果。public class Test public static void main(String args) new Student(Tom, m, 90, 88); new Student(Jack, m, 66, 89); new Student(Mary, f, 76, 86); System.out.println(nametsextchinesetenglish); Student.print(); class Student protected String name; protected char sex; protected int chinese; protected int english; protected Student next; static Student list; Student (String name, char sex, int chinese, int english) =name; this.sex=sex; this.chinese=chinese; this.english=english; this.next=list; list=this; static void print() Student friend=list; if (friend=null) System.out.println(The list is empty.); else do System.out.println(friend.toString(); friend=friend.next; while(friend!=null); public String toString() return new String(name+t+sex+t+chinese+t+english); 答案:name sex chinese englishMary f 76 86Jack m 66 89Tom m 90 8823、閱讀下列程序:public class Sumpublic static void main(String args)int j=10;System.out.println(j is : +j);calculate(j);System.out.println(At l
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- CJ/T 163-2002導(dǎo)流型容積式水加熱器和半容積式水加熱器(U型管束)
- CJ/T 105-1999城市生活垃圾全鉀的測(cè)定火焰光度法
- 2025年軟件評(píng)測(cè)師考試突破技巧及試題及答案
- 多媒體設(shè)計(jì)的技術(shù)利用與創(chuàng)新策略試題及答案
- 深入理解系統(tǒng)分析師考試內(nèi)容試題及答案
- 豐富的2025年信息管理考試相關(guān)MS Office試題及答案
- 木材市場(chǎng)倉庫管理制度
- 退貨與召回管理制度
- 服務(wù)對(duì)象反饋的處理試題及答案
- 藥房藥品追溯管理制度
- 安徽理工大學(xué)《先進(jìn)制造技術(shù)》2021-2022學(xué)年第一學(xué)期期末試卷
- 藥物警戒培訓(xùn)課件
- 2023年高考遼寧卷化學(xué)真題(解析版)
- 2023年上海市閔行區(qū)區(qū)管國企招聘筆試真題
- 三年級(jí)道德與法治下冊(cè) 第一單元 我和我的同伴 4同學(xué)相伴教案 新人教版
- 2025年黑龍江省海倫市第四中學(xué)初三年級(jí)4月聯(lián)考物理試題含解析
- 云南省昭通市鎮(zhèn)雄縣2023-2024學(xué)年五年級(jí)下學(xué)期期末英語試題+
- 管培生培養(yǎng)方案
- 江蘇省淮安市淮陰區(qū)淮陰中學(xué)2025屆高一下生物期末質(zhì)量檢測(cè)試題含解析
- 2024屆江蘇省淮安市數(shù)學(xué)高一下期末考試試題含解析
- 2024年安徽六安裕安投資集團(tuán)裕安融資擔(dān)保有限公司招聘筆試參考題庫含答案解析
評(píng)論
0/150
提交評(píng)論