java程序设计作业答案

上传人:公**** 文档编号:512881693 上传时间:2023-03-27 格式:DOC 页数:18 大小:71.01KB
返回 下载 相关 举报
java程序设计作业答案_第1页
第1页 / 共18页
java程序设计作业答案_第2页
第2页 / 共18页
java程序设计作业答案_第3页
第3页 / 共18页
java程序设计作业答案_第4页
第4页 / 共18页
java程序设计作业答案_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《java程序设计作业答案》由会员分享,可在线阅读,更多相关《java程序设计作业答案(18页珍藏版)》请在金锄头文库上搜索。

1、JAVA程序设计作业答案一、选择题1、 编译HelloWorld.java的正确命令是:C) javac HelloWorld.java2、 正确运行HelloWorld.java的正确命令是:A)java HelloWorld3、 下面程序代码,使用多行注释正确的是:C) /* int k=9; int j=8; k = k + j; */4、 long型的取值范围是:D)-263263-15、 下面不属于Java保留字的是:C)malloc6、 下面属于非法的Java标识符的是:D) abc-d7、 对与System.out.println()语句解释合理的是:C)执行后输出一个空行8、

2、阅读下面的代码,回答问题,for( m = 0 ; m -2 ; m - ).For循环执行多少次:C)29、 阅读下面的代码,回答问题,for( m = 0; m 5; m+ ) System.out.print( m + , );if( m = 3 ) break;执行结果是:C)0,1,2,3,10、 阅读下面的代码,回答问题,public class Exint x = 1;void m()int x = 3; System.out.print( x= + x);public static void main( String args )Ex ex = new Ex();ex.m();

3、执行结果是:B)x=3 11、下面语句在编译时不会出现错误信息的是:a) float f = 1.3; b) char c = a; c) byte b = 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.

4、out.println(arguments1);a) 错误,静态方法不能直接引用非静态方法 b) 错误,主方法有错误c) 错误,数据定义有错误 d) 方法amethod必须被声明为String型13、编译期间会出错的是:a) import java.awt.*; package Mypackage; class Myclass b) package MyPackage; import java.awt.*; class MyClassc) /*This is a comment */ package MyPackage; import java.awt.*; class MyClass14、b

5、yte型的变量的表示范围为:a) -128 to 127 b) (-2 power 8 )-1 to 2 power 8c) -255 to 256 d) 依赖Java虚拟机而定15、在命令行运行命令:java myprog good morning会有什么结果显示出来:public class myprogpublic static void main(String argv) System.out.println(argv2)a) myprog b) good c) morningd) Exception raised: java.lang.ArrayIndexOutOfBoundsExc

6、eption: 216、下面不是Java保留字的是:a) if b) then c) goto d) while17、下面属于非法的标识符的是:a) 2variable b) variable2 c) _whatavariable d) _3_ e) $anothervar18、编译下面的代码,会有什么结果产生:public class MyClassstatic int i; public static void main(String argv)System.out.println(i); a) 错误,变量i 没有初始化 b) null c) 1 d) 019、编译运行下面的代码,会有什么

7、结果产生:public class Q public static void main(String argv)int anar= new int1,2,3;System.out.println(anar1); a) 1 b) 3 c) 2 d) 错误,数组anar的长度没有定义20、编译运行下面的代码,会有什么结果产生:public class Q public static void main(String argv)int anar= new int5;System.out.println(anar0); a) 编译错误 b) null c) 0 d) 5 Arrays are alwa

8、ys initialised when they are 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 MineBasepublic static void main(String argv)int ar = new int5;for(i = 0;i ar.length;i+)Syst

9、em.out.println(ari);a) 五个0被输出 b) 错误,ar使用前没有初始化c) 错误,类Mine 必须要被声明为抽象的类 d) IndexOutOfBoundes Error i22、编译运行下面的代码,会有什么结果产生:int i = 1;switch (i) case 0:System.out.println(zero);break;case 1:System.out.println(one);case 2:System.out.println(two);default:System.out.println(default);a) one b) one, default

10、c) one, two, default d) default23、编译运行下面的代码,会有什么结果产生:int i = 9;switch (i) default:System.out.println(default);case 0:System.out.println(zero);break;case 1:System.out.println(one);case 2:System.out.println(two);a) default b) default, zero c) error default clause not defined d) no output displayed24、下

11、面不会在编译时出错的是:a) int i=0; if(i) System.out.println(Hello); b) boolean b = true; boolean b2 = true; if(b=b2) System.out.println(So true);c) int i=1; int j = 2; if(i =1j=2) System.out.println(OK);d) int i=1; int j = 2; if(i =1 &| j=2) System.out.println(OK);25、编译运行下面的代码,会有什么结果产生,注意,在当前目录里没有文件Hello.txt:i

12、mport java.io.*;public class Mine public static void main(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 i

13、oe) finallySystem.out.println(Doing finally);return 0;a) No such file found b)No such file found ,-1c) No such file found, doing finally, -1 d) 026、建立一个HTML去显示一个applet时,必须要定义的tags是:a) name, height, width b) code, name c) codebase, height, width d) code, height, width27、编译运行下面的代码,会有什么结果产生:class Base class Sub extends Base public class CExpublic static void main(String argv)Base b = new Base();Sub s = (Sub) b;a) Compile and run witho

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号