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

开通VIP
 

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

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

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(2024年java程序设计作业答案.doc)为本站上传会员【精****】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

2024年java程序设计作业答案.doc

1、《JAVA程序设计》作业答案 一、选择题 1、 编译HelloWorld.java的正确命令是: C) javac HelloWorld.java 2、 正确运行HelloWorld.java的正确命令是: A)java HelloWorld 3、 下面程序代码,使用多行注释正确的是: C) /* int k=9; int j=8; k = k + j; */ 4、 long型的取值范围是: D)-263~263-1 5、 下面不属于Java保存字的是: C)malloc 6、 下面属于非法的Java标识符的是: D)

2、abc-d 7、 对与System.out.println()语句解释合理的是: C)执行后输出一个空行 8、 阅读下面的代码,回答下列问题, for( m = 0 ; m > -2 ; m -- ){….} For循环执行多少次: C)2 9、 阅读下面的代码,回答下列问题, for( m = 0; m < 5; m++ ) { System.out.print( m + "," ); if( m == 3 ) break; } 执行成果是: C)0,1,2,3, 10、 阅读下面的代码,回答下列问题, p

3、ublic class Ex { int x = 1; void m() { int x = 3; System.out.print( "x= " + x); } public static void main( String[] args ) { Ex ex = new Ex(); ex.m(); } } 执行成果是: B)x=3 11、下面语句在编译时不会出现错误信息的是: a) float f = 1.3; b) char c = "a"; c) byte b =

4、 257; d) boolean b = null; e) int i = 10; 12、编译和运行下面的代码,会有什么成果产生: public class MyClass { public static void main(String arguments[]) { amethod(arguments); } public void amethod(String[] arguments) { System.out.println(arguments); System.out.println(arguments[1]); } } a)

5、错误,静态措施不能直接引用非静态措施 b) 错误,主措施有错误 c) 错误,数据定义有错误 d) 措施amethod必须被申明为String型 13、编译期间会犯错的是: a) import java.awt.*; package Mypackage; class Myclass {} b) package MyPackage; import java.awt.*; class MyClass{} c) /*This is a comment */ package MyPackage;

6、 import java.awt.*; class MyClass{} 14、byte型的变量的表示范围为: a) -128 to 127 b) (-2 power 8 )-1 to 2 power 8 c) -255 to 256 d) 依赖Java虚拟机而定 15、在命令行运行命令:java myprog good morning 会有什么成果显示出来: public class myprog{ public static void main(String argv[]) { System.out.println(arg

7、v[2]) } } a) myprog b) good c) morning d) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2" 16、下面不是Java保存字的是: a) if b) then c) goto d) while 17、下面属于非法的标识符的是: a) 2variable b) variable2 c) _whatavariable d) _3_ e) $anothervar 18、编译下面的代码,会有什么成果产生:

8、 public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } } a) 错误,变量i 没有初始化 b) null c) 1 d) 0 19、编译运行下面的代码,会有什么成果产生: public class Q { public static void main(String argv[]){ int anar[]= new int[]{1,2,3}; System.out.print

9、ln(anar[1]); } } a) 1 b) 3 c) 2 d) 错误,数组anar的长度没有定义 20、编译运行下面的代码,会有什么成果产生: public class Q { public static void main(String argv[]){ int anar[]= new int[5]; System.out.println(anar[0]); } } a) 编译错误 b) null c) 0 d) 5 Arrays are always initialised when they are

10、created. As this is an array of ints it will be initalised with zeros. 21、编译运行下面的代码,会有什么成果产生: abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar = new int[5]; for(i = 0;i < ar.length;i++)

11、 System.out.println(ar[i]); } } a) 五个0被输出 b) 错误,ar使用前没有初始化 c) 错误,类Mine 必须要被申明为抽象的类 d) IndexOutOfBoundes Error i 22、编译运行下面的代码,会有什么成果产生: int i = 1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.o

12、ut.println("two"); default: System.out.println("default"); } a) one b) one, default c) one, two, default d) default 23、编译运行下面的代码,会有什么成果产生: int i = 9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println(

13、"one"); case 2: System.out.println("two"); } a) default b) default, zero c) error default clause not defined d) no output displayed 24、下面不会在编译时犯错的是: a) int i=0; if(i) { System.out.println("Hello"); } b) boolean b = true; boolean b2 = true; if(b==b2) Sy

14、stem.out.println("So true"); c) int i=1; int j = 2; if(i ==1&j==2) System.out.println("OK"); d) int i=1; int j = 2; if(i ==1 &| j==2) System.out.println("OK"); 25、编译运行下面的代码,会有什么成果产生,注意,在目前目录里没有文献Hello.txt: import java.io.*; public class Mine { public static void main(

15、String argv[]){ Mine m = new Mine(); System.out.println(m.amethod()); } public int amethod() { try { FileInputStream dis = new FileInputStream("Hello.txt"); }catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1; }catch(IOException ioe) { } finally{ Sys

16、tem.out.println("Doing finally"); } return 0; } } a) No such file found b)No such file found ,-1 c) No such file found, doing finally, -1 d) 0 26、建立一个HTML去显示一个applet时,必须要定义的tags是: a) name, height, width b) code, name c) codebase, height, width d) code, heigh

17、t, width 27、编译运行下面的代码,会有什么成果产生: class Base {} class Sub extends Base {} public class CEx{ public static void main(String argv[]){ Base b = new Base(); Sub s = (Sub) b; } } a) Compile and run without error b) Compile time Exception c) Runtime Exception 28、用下面的HTML去显示applet:MgAp,控制

18、台会有什么成果显示: import java.applet.*; import java.awt.*; public class MgAp extends Applet{ public void init(){ System.out.println(getParameter("age")); } } a) Error no such parameter b) 0 c) null d) 3

19、0 参数age没有取得从HTML给定的值,因此显示null. 29、Math类包括在哪个包里: a) java.io b) java.awt c) java.lang d) java.applet 30、编译运行下面的代码,会有什么成果产生://Code start import java.awt.*; public class Butt extends Frame{ public static void main(String argv[]){ Butt MyBut= new Butt(); } Butt(){ Button HelloBut =

20、 new Button("Hello"); Button ByeBut = new Button("Bye"); add(HelloBut); add(ByeBut); setSize(300,300); setVisible(true); } } //Code end a) 两个按钮并列占据整个frame b) Hello按钮占据整个frame c) Bye按钮占据整个frame The default layout manager for a Frame is a border layout. If directions are not given

21、ie North, South, East or West), any button will simply go in the centre and occupy all the space. An additional button will simply be placed over the previous button. What you would probably want in a real example is to set up a flow layout as in setLayout(new FlowLayout()); which would. 31、Java程

22、序是否能够在除了Windows的其他平台上运行: A) 不能够 B)能够 32、对于一个Java源文献,import, class定义以及package正确的次序是: A)package, import, class B)class, import, package C)import, package, class D) package, class, import 33、那个措施能够不能被String型对象调用: Which methods can be legally applied to a

23、string object? A) equals(String) B)toString() B) trim() D)round() 34、main措施中的参数正确的定义是: A) String[] args [] B)String [] args B) float args [] D)String args 35、在命令行执行:java Example 12 3e you 45.6 那么main措施的参数args数组的第一个元素args[0]的内容是: Java

24、B)Example C)12 D)3e 36、下面那个不是Java的核心字: A) goto B)malloc B) extends D)while 37、编译下面的代码,成果是: public class Test { public static void main (String args []) { int age; age = age + 1; System.out.println("The age is " + age); } } A)编译运行都没有成果输出 B)编译运行后输出 The age is 1 C)编译通过,但

25、运行时会犯错 D)编译不通过 38、下面合法的char型值是: A)‘a’ B)"a" C) new Character(a) D) D)\000a 39、能够给一个byte型变量赋值的范围是: What is the legal range of a byte integral type? A)0 - 65, 535 B)(–128) – 127 C)(–32,768) – 32,767 D)(–256) – 255 40、下面哪个是非法的: Which of the following i

26、s illegal: A)int i = 32; B)float f = 45.0; C)double d = 45.0; D)char c = ‘u’ 41、编译下面的代码,其成果是: public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); } } A)编译运行都没有成果输出 B)编译运行后输出 The age is 1 C)

27、编译通过,但运行时会犯错 D)编译不通过 42、下面正确的是: Which of the following are correct? A)128 >> 1 为 64 B)128 << 1为64 C)128 >> 1为–64 D)128 << 1为–64 43、下面返回true的是: A)"john" != "john" B)"john". equals("john") C)"john" = "john" D)"john".equals(new Button("john")) 44

28、下面哪条语句不会导致运行时错误: A)"john" + " was " + " here" B)"john" + 3 C)3 + 5 D)5 + 5.5 E)以上四个都不会导致运行时错误 45、下面哪个是位运算符: A)>= B)|| C)&& D)| 46、下面那个是能够被接收的: A)Object o = new Button("A"); B)Boolean flag = true; C)Panel p = new Frame();

29、 D)Frame f = new Panel(); 47、编译运行下面代码,其成果是: public class Test { static int total = 10; public static void main (String args []) { new Test(); } public Test () { System.out.println("In test"); System.out.println(this); int temp = this.total; if (temp > 5) { System.out.println(t

30、emp); } } } A)此类不会被编译 B)编译犯错在第2行 C)编译犯错在第9行 D)编译通过,运行后输出:10 48、下面正确的是: A)String temp [] = new String {"j" "a" "z"}; B)String temp [] = { "j " " b" "c"}; C)String temp = {"a", "b", "c"}; D)String temp [] = {"a", "b", "c"}; 49、下面定义了一个抽象措施add,正确的是: What is

31、 the correct declaration of an abstract method that is intended to be public: A)public abstract void add(); B)public abstract void add() {} C)public abstract add(); D)public virtual add(); 500、在什么情况下,你会取得一个缺省的结构措施: A)当你定义任何类的时候 B)当类没有其他结构措施的时候 C)当你最少定义了一个结构措施的时候 51、阅读下

32、面的代码: public class Test { … } 那个是这个类的合法结构措施: A)public void Test() {…} B)public Test() {…} C)public static Test() {…} D)public static void Test() {…} 52、Java编译器不能接收的是: A)if (2 == 3) System.out.println("Hi"); B)if (2 = 3) System.out.println("Hi"); C)if (true) System.out.pri

33、ntln("Hi"); D)if (2 != 3) System.out.println("Hi"); 53、若一个措施包括了一段也许引起异常的代码,那么此措施想要调用他的措施去处理这个潜在的异常的正确措施是: A)throw Exception B)throws Exception C)new Exception D)Don't need to specify anything 54、若给参数a传递4,给b传递0,那么下面程序的成果是: public void divide(int a, int b) { try { int

34、 c = a / b; } catch (Exception e) { System.out.print("Exception "); } finally { System.out.println("Finally"); } A)Prints out: Exception Finally B)Prints out: Finally C)Prints out: Exception D)No output 55、编写一个措施重载题目给出的措施add,那么他的返回类型能够是: public void add(int a) {…} A)v

35、oid B)int C)能够是任何类型 D)String  56、合法的Java标示符有: A. IdoLikeTheLongNameClass B. $byte C. const //保存字 D. _okE. 3_case 57下面这段代码中定义的类在不一样的文献中: class Vehicle { public void drive() { System.out.println("Vehicle: drive"); } } class Car extends Vehicle { public void drive() {

36、 System.out.println("Car: drive"); } } public class Test { public static void main (String args []) { Vehicle v; Car c; v = new Vehicle(); c = new Car(); v.drive(); c.drive(); v = c; v.drive(); } } 编译运行的成果是: A)Generates a Compiler error on the statement v= c; B)Generates runtime er

37、ror on the statement v= c; C)输出: Vehicle: drive Car: drive Car: drive D)输出Prints out: · Vehicle: drive Car: drive Vehicle: drive 58、考虑下面的这个类: 1. public class Test { 2. void test(int i) { 3. System.out.println("I am an int."); 4. } 5. void test(String s) { 6. System.out.println

38、"I am a string."); 7. } 8. 9. public static void main(String args[]) { 10. Test t=new Test(); 11. char ch=’y’; 12. t.test(ch); 13. } 14. } 哪一个阐明是正确的: A. 第5行编译犯错,因为措施test不能被重载 B. 第12行编译犯错,因为措施test的参数不是char类型 C. 编译运行通过,输出:I am an int. D. 编译运行通过,输出:I am a String. 点评:在第12行,16位长的char型变量ch在

39、编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)措施。 59、一个类Outer,其内部定义了一个内部类Inner,在Outer类的主措施中创建内部类对象的正确措施是: A)Inner inner = new Inner() B)Outer.Inner inner = (new Outer()).new Inner() C)Outer inner = new Inner() D)Inner inner = new Outer() 60、当x的值为2时,下面代码的运行成果是: switch (x) { case

40、 1: System.out.println(1); case 2: case 3: System.out.println(3); case 4: System.out.println(4); } A)什么都不会输出 B)3 C)34 D)134 1、4) double d=999d; 2、2) new 3、1) System.out.println(1+1); 4、2) Math.max(7,9); 5、1) byte 的表示范围为 -128 to 127 6、2) 编译运行通过,输出 Base 7、2) public static v

41、oid amethod(){} 8、1) char c=’1’; System.out.println(c>>1); 9、3) transient 10、2) 输出 “Hello Crowle” 二、改错 1、答案:public static void main(String[] args) 2、答案:public class Ex2 { int j; public static void main(String[] args) { System.out.println(“Hello World!”); } } 3、答案

42、z = a + b ; 4、答案: 1)int b = 200; 2) float f = 8.9f 3) char c = ‘h’ 4) boolean b = true 5、答案: public class Ex5 { int x = 1; int y = 1; x = 2; } 6、答案: public class Ex6 { int x = 1; int y = 1; public static void main(String[] args ) { System.out.print(

43、 “Hello” ); } } 7、package mycode.ide1; package mycode.ide2; public class Ex1 { …. } 答案:不能有两个package 8、import mycode.ide1.*; package mycode.ide2; public class Ex2 { …. } 答案:imports和package 次序颠倒 9、 public abstract class Ex3 { void m1() { System.out.println( “m1” ); }

44、 void m2(); } 答案:措施m2应当被申明为abstract,或者给出m2的措施体 10、public interface Ex4 { int j; void m1(){}; void m2(); } 答案:接口中的变量都是常量,应当给他赋初值;接口中的措施都是抽象措施,而m1不是抽象措施 11、interface Parent { int j = 1; void m1(); } public class Ex5 extends Parent { void m1() { System.out.pri

45、nt( “m1 in child” ); } } 答案:将extends 改为implements 12、interface Parent1 { void m1(); } interface Parent2 { void m2(); } public class Ex6 implements Parent1, Parent2 { void m1() { System.out.print( “m1 in child” ); } } 答案:措施m2没有在Ex6中详细定义 13、 下面程序有什么错误?请指出并更

46、正。 public class Base { public static void main(String argv[]) { int[][] t = { {1,2,3},{4,5},{6} }; try { System.out.print(t[1][2]); } catch( IOException e ) { e.printStackTrace(); } System.out.print( "Ends OK" ); } } 答:把IOException改为Exception

47、 14、下面程序有什么错误?请指出并更正。 public class ExArray { public static void main(String argv[]) { int[][] t = { {1,2,3},{4,5},{6} }; try { System.out.print(t[1][2]); } System.out.print( "after try block" ); catch( Exception e ) { e.printStackTrace(); } System.o

48、ut.print( "after catch block" ); } } 答:在try 和catch之间不能出现任何语句。因此去掉System.out.print( "after try block" ); 15、更正下面代码的错误: int[] a = new int[3]; a[0] = 1; a[1] = 2.0; a[2] = 3; 答:把a[1] = 2.0改为a[1] = 2 三、名词解释 1、 重置:在继承类之间,子类和其父类都有一个同名的措施,该措施的措施头完全一致,子类对象调用这个措施时,实际调用的是自己的,而非其父的

49、这种现象叫~ 2、 异常:程序在运行期间,出现错误而不能正常退出,这种现象叫~ 3、 Java虚拟机: 在真实机器中用软件模拟实现的一个想象机器。Java虚拟机代码被存储在 .class文献中;每个文献都包括最多一个public类。Java虚拟机规范为不一样的硬件平台提供了一个编译Java技术代码的规范,该规范使Java软件独立于平台,因为编译是针对作为虚拟机的“一般机器”而做,这个“一般机器”可用软件模拟并运行于各种现存的计算机系统,也可用硬件来实现。 4、 节点流:直接提供输入输出功效的流 5、 处理流:高级流,增强了节点流的功效 四、问答题 1、答案:choice =

50、 2 choice = 3 choice = default 2、解释重载的概念。 3、 答案:Ex6 obj = new Ex6( 3 ) 4、请写出所有的关系运算符以及逻辑运算符。 答案:> < >= <= != == ! && || ^ 简明解释下面存取控制符的作用。 public protected privat 答案:1)任何类都可访问 2)继承类和同一软件包的类可访问 3)只有在其修饰的数据和措施所在类可访问 5、下面的体现式会产生100以内的随机整数吗? 100*Math.r

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服