java专题作业答案_《java程序设计》作业答案
《java程序设计》作业答案
《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) 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、 阅读下面的代码,回答问题, public 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 = 257; d) boolean b = null; e) int i = 10; 12、编译和运行下面的代码,会有什么结果产生: public class MyClass { public static void main(String arguments[]) { a(arguments); } public void a(String[] arguments) { System.out.println(arguments); System.out.println(arguments[1]); } } a) 错误,静态方法不能直接引用非静态方法 b) 错误,主方法有错误 c) 错误,数据定义有错误 d) 方法a必须被声明为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; 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(argv[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、编译下面的代码,会有什么结果产生: 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.println(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 created. As this is an array of ints it will be initalised with zeros. 21、编译运行下面的代码,会有什么结果产生: abstract class MineBase { abstract void a(); 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++) Syst