2020年春季学期课程作业Java程序设计第3次13625131-重庆大学网络教育学院-参考资料_第1页
2020年春季学期课程作业Java程序设计第3次13625131-重庆大学网络教育学院-参考资料_第2页
2020年春季学期课程作业Java程序设计第3次13625131-重庆大学网络教育学院-参考资料_第3页
2020年春季学期课程作业Java程序设计第3次13625131-重庆大学网络教育学院-参考资料_第4页
2020年春季学期课程作业Java程序设计第3次13625131-重庆大学网络教育学院-参考资料_第5页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、重庆大学网络教育学院-2020年春季学期课程作业Java程序设计第3次-参考资料请认真阅读一下说明然后下载:题库有可能会换,不保证全部都有!请仔细核对是不是您需要的题目再下载! ! ! !本文档的说明:如果题目顺序和你的试卷不一样,按CTRL+F 在题库中逐一搜索每一道题的答案,预祝您取得好成绩百!一 、 程序阅读题 (共 10 题、 0 / 40 分 )1 、 import java.io.* ;public class Reversepublic static void main(String args ) int i , n =5 ;int a = new int5;for ( i =

2、0 ; i = 0 ; i- )System.out.print(ai+ );System.out.println( );如果从键盘输入 1 2 3 4 5 则运行结果为 :参考答案是: 5 4 3 2 12 、 class testpublic static void main(String args)int x=4,j=0;switch(x)case 1: j+;case 2: j+;case 3: j+;case 4: j+;case 5: j+;break;default: j+;System.out.println(j);参考答案是: 23 、 public class Leafpr

3、ivate int i=0;Leaf increment( )i+;return this;void print( )System.out.println( “ i= ” +i);public static void main(String args)Leaf x=new Leaf( );x.increment( ).increment( ).increment( ).print( );参考答案是:i=34 、 import java.io.*;public class testpublic static void main(String argv)test m=new test();Syst

4、em.out.println(m.amethod();public int amethod()tryFileInputStream dis=new FileInputStream(Hello.txt);catch (FileNotFoundException fne)System.out.println(No such file found);return -1;catch(IOException ioe)finally System.out.println(Doing finally);return 0;如果文件 Hello.txt 并不存在,则运行结果是参考答案是: No such fil

5、e found Doing finally -15 、 public class teststatic StringBuffer sb1=new StringBuffer(Hello);static StringBuffer sb2=new StringBuffer(Hello);public static void main(String args)aMethod(sb1,sb2);System.out.println(sb1 is +sb1);System.out.println(sb2 is +sb2);public static void aMethod(StringBuffer sb

6、1,StringBuffer sb2) sb2.append( there);sb1=sb2;参考答案是: sb1 is Hello sb2 is Hello there6 、 class Baseint x=3;public Base() public void show()System.out.println( The value is +x);class Derived extends Baseint x=2;public Derived() public void show()System.out.println( The value is +x);public class testp

7、ublic static void main(String args)Base b = new Derived();b.show();System.out.println(The value is +b.x);参考答案是: The value is 2 The value is 37 、 interface Fooint k=0;public class test implements Foopublic static void main(String args)int i;test t =new test();i=t.k;i=test.k;i=Foo.k;System.out.println

8、(i);参考答案是: 08 、 public class Testpublic static void main(String args)String foo=args0;String bar=args1;String baz=args2;System.out.println(baz);如果执行语句 java Test Red Green Blue 后结果为 参考答案是: Blue9 、 public class testString s1 = Initialized at definition;String s2;public test(String s2i)s2 = s2i;public

9、static void main(String args) test si =new test(Initialized at construction);System.out.println(si.s1 = + si.s1);System.out.println(si.s2 = + si.s2);参考答案是: si.s1 = Initialized at definition si.s2 = Initialized at construction10 、 public class Test public static String output = ;public static void fo

10、o(int i)try if(i=1)throw new Exception ();output += 1;catch(Exception e)output += 2;return; finally output += 3; output += 4;public static void main (String args)foo(0);foo(1);System.out.println(output);参考答案是: 13423二 、 简答题(共 5 题、 0 / 20 分 )1 、什么是对象?如何创建一个对象?参考答案是: 对象是对客观事物的抽象,是类的实例.在面向对象的程序设计题中,把问题域

11、中的事物抽象成对象,将事物的静态特征用一组数据描述,将事物的动态特征用一组方法来刻画. 创建对象由以下三步完成: (1) 声明对象.其格式是: 类名 对象名表 (2) 建立对象,也就是为对象分配内存.其格式是:对象名=new构造方法()或类名 对象名=new构造方法()(3) 初始化对象 ,即为它的数据成员赋初值.2、消息的基本构成?参考答案是: 消息包括:接受消息的对象、接受消息的对象应执行的方法 、方法所需要的3、指出运算符“=”和方法equals()在判断题对象是否相等上的区别?参考答案是:equals()是判断题两个对象对应的取值是否相等“=”是判断题两个对象是否是同一个对象.4、下列

12、代码不能正确编译的原因是什么?class Apublic static void main(String args)B b = new B();b.x=5; class Bprivate int x;Show()System.out.println(x);参考答案是: 私有变量的使用限制 .5、简述面向对象程序的主要特征参考答案是: 面向对象程序的主要特征是封装性,继承性和多态三 、 程序设计题 (共 5 题、 0 / 40 分 )1 、给定一个字符串数组String f = ab, bc, cd, de, ef; 编程实现从该数组中查找用户指定字符串位置的功能,用户指定的字符串由命令行参数输

13、入 .参考答案是: public class testpublic static void main(String args)int i, j = 0;String s = args0;String f = ab, bc, cd, de, ef;for (i = 0; i 4; i+) if (pareTo(fi) = 0) System.out.print(the position is + i);j = 1;if (j = 0) System.out.print(no such string);2 、编写程序使用类 StringBuffer 的 replace 方法将字符串” Mary w

14、as a ”改为” Mary had a book. ”参考答案是:import java.util.*;public class String_testpublic static void main(String args)StringBuffer str1=new StringBuffer ( “ Mary was a ” );StringBuffer str2=str1.replace(5,10,” had a book. ” );System.out.println(str2); 3 、编程将键盘输入的数据拷贝当前路径下test.txt 中,如果遇到 quit 就结束程序。参考答案是:

15、public class Test2 public static void main(String args) throws IOException Scanner sc = new Scanner(System.in);FileOutputStream fos = new FileOutputStream(text.txt);while(true) String line = sc.nextLine();if(quit.equals(line) break;else fos.write(line.getBytes(); / 字符串转换字节fos.write(rn.getBytes(); / 换行fos.close();4、编程将一个浮点型数(如 23.56) 的整数部分和小数分别输出显示。参考答案是:import java.io.*;public class pro2_2public static void main(String args) double d=23.56,dl;d1=d;int n=0;while(true) d-;if(d0)break;n+System.out.println(integer=+n+,d

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论