ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:19.83KB ,
资源ID:28746823      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/28746823.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java复习题阅读程序题.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java复习题阅读程序题.docx

1、Java复习题阅读程序题Java复习题阅读程序题 Java复习题阅读程序题 JAVA程序设计复习题之(三)阅读程序题 (通信工程专业使用) 三、阅读程序题。 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 pu

2、blic 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= + s

3、um); 此程序完成的功能是: 计算并输出1到100的立方和sum值。 4、阅读以下程序: public class Sum Java复习题阅读程序题 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 p

4、ublic 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); 请写出此程序的输出结果: s=180 6、阅读以下程序 import java.io.*; public class abc public static void main(String args ) AB s = new AB(Great!,

5、I love Eclipse.); System.out.println(s.toString( ); class AB String s1; String s2; public AB(String str1, String str2) Java复习题阅读程序题 s1 = str1; s2 = str2; public String toString( ) return s1 + s2; 运行结果是: 运行结果是:Great! I love Eclipse. 7、阅读以下程序 import java.io.* ; public class abc public static void main

6、(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); 运行结果是: 运行结果:s = 180 8、阅读以下程序 import java.io.* ; public class abc public static void main(String args ) System.out.println(a= + a +

7、 nb= + b); class SubClass extends SuperClass int c; SubClass(int aa, int bb, int cc) super(aa, bb); Java复习题阅读程序题 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); 运行结果是: 运行结果:

8、a=60 b=20 c=30 9、以下程序的输出结果为相等 class StringTest1 10、以下程序段的输出结果为 5 6 7 8 9 。 public class TestArray public static void main(String args ) 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(不相等); int i ,

9、 j ; int a = 5,9,6,8,7; for ( i = 0 ; i a.length-1; i + ) Java复习题阅读程序题 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

10、 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(请输入一个字符串: ); System.out.flush( ); s = br.readLine( ); if (s.length() = 0) brea

11、k; bw.write(s); bw.newLine(); bw.close( ); 程序功能是: 程序功能是:从键盘逐一输入字符串,逐一输出至input.txt文件中,直至输入空行。 Java复习题阅读程序题 12、阅读以下程序,写出输出结果。 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();

12、输出结果是: 输出结果是:Animal Dog 13、以下程序的输出结果为 Peter is 17 years old! public class Person 14、以下程序的输出结果为课程号:101 课程名:JSP 学分:3。 public class Course 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.

13、println( + is + c.age + years old!); private String cNumber; private String cName; private int cUnit; public Course(String number, String name, int unit) Java复习题阅读程序题 cName = name; cUnit = unit; public void printCourseInfo() System.out.println(课程号: + cNumber + 课程名: + cName + 学分: + cUnit); class Cour

14、seTest 15、以下程序的输出结果为汤姆猫体重:20.0斤。 public class Tom public static void main(String args) = 汤姆猫; private void out() System.out.println(name + 体重: + weight + 斤); public void setWeight(float weight) this.weight = weight; private float weight; private static String name; public static void main(String arg

15、s) Course c; c = new Course(101, JSP, 3); c.printCourseInfo(); Java复习题阅读程序题 cat.setWeight(20); cat.out(); 16、以下程序的输出结果是姓名:Tom 年龄:15 家庭住址:宿城区 电话:_-_ 学校:宿中_。 public class Father class Son extends Father String school; public Son(String name, int age) void out() super.out(); super.outOther(); super(nam

16、e, age); public Father(String name, int age) void out() void outOther() System.out.print( 家庭住址: + address); System.out.print( 电话: + tel); System.out.print(姓名: + name); System.out.print( 年龄: + age); = name; this.age = age; String name, address, tel; int age; Java复习题阅读程序题 public static void main(Strin

17、g args) Son son = new Son(Tom, 15); son.address = 宿城区; son.school = 宿中; son.tel = _-_; son.out(); 17、下列程序的运行结果是_。 public class MyClass 18、阅读下面的程序,回答问题。 import java.awt.*; public static void main(String args) MyClass my = new MyClass(); my.out(); void out() for (int j = 0; j a.length; j+) System.out.

18、print(aj + ); int a = 1, 2, 3, 4, 5 ; 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); Java复习题阅读程序题 con.add(new JButton(b); con.add(new JButton(c); con.add(new JButton(d

19、); con.add(new JButton(e); con.add(new JButton(f); setSize(200, 80); setVisible(true); public static void main(String args) new T(); 画图表示程序运行后的图形界面。 如果程序通过实现某个接口处理按钮的动作事件,则该接口名为何?接口中的方法头声明如何? 答案: 接口名:ActionListener 接口中的方法:public void actionPerformed(ActionEvent e) 19、阅读下面的程序,并回答问题。 import java.io.*;

20、 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(_); Java复习题阅读程序题 编译运行上面的程序: 从

21、键盘输入5,回车后输出的结果如何? 从键盘输入quit,回车后程序执行情况如何? 答案: 25 终止应用程序的运行。 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); 程序段执行后,在命令行的输出结果如何? 解释输出(1)的结果的原因? 答案: true false equals方法比较两个字符串的内容是否相等;运算符“=”判断两个对

22、象是否指向同一个引用,即是否为同一个对象。 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.parseIn

23、t(str); System.out.println(_); 编译运行上面的程序: Java复习题阅读程序题 从键盘输入10,回车后输出的结果如何? 从键盘输入exit,回车后程序能正确执行吗?为什么? 答案: 100 不能;因为方法Integer.parseInt(str)不能将字符串“exit”转化为整数,抛出异常。 22、写出下面的程序编译、运行后的结果。 public class Test public static void main(String args) new Student(Tom, m, 90, 88); new Student(Jack, m, 66, 89); new

24、 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) =nam

25、e; this.sex=sex; this.chinese=chinese; this.english=english; this.next=list; list=this; static void print() Student friend=list; Java复习题阅读程序题 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

26、toString() return new String(name+t+sex+t+chinese+t+english); 答案: name sex chinese english Mary f 76 86 Jack m 66 89 Tom m 90 88 23、阅读下列程序: public class Sum public static void main(String args) int j=10; System.out.println(j is : +j); calculate(j); System.out.println(At last, j is : +j); static void

27、 calculate (int j) 输出结果为: j is : (1) for (int i = 0;ii+) j+; System.out.println(j in calculate() is: +j); Java复习题阅读程序题 j in calculate() is : (2) At last j is : (3) 答案:(1) 10; (2) 20; (3) 10。 24、按要求填空 abstract class SuperAbstract interface AsSuper abstract class SubAbstract extends SuperAbstract impl

28、ements AsSuper public void b( )。 public class InheritAbstract extends SubAbstract 在以上这段程序中: 抽象类有:SuperAbstract和 (1) (写出类名) 非抽象类有: (2) (写出类名) 接口有: (3) (写出接口名) public void x( ) 。 public int c(int i ) 。 public String f( ) 。 public static void main(String args) InheritAbstract instance = new InheritAbst

29、ract( ); instance.x(); instance.a(); instance.b(); instance.c(100); System.out.println(instance.f(); abstract String f( ); void x( ); void a()。 abstract void b(); abstract int c(int i); Java复习题阅读程序题 AsSuper中的x()方法是(4)方法,所以在InheritAbstract中必须对它进行(5) 答案: (1) SuperAbstract; (2) InheritAbstract; (3) AsSuper; (4) 抽象; (5) 覆盖和实现。 25、按注释完成程序 public class Leaf 输出结果为 i = (3) _ 答案: (1) this; (2) new Leaf(); (3) 3 26、 按注释提示完成文件复制的程序 /FileStream源代码

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1