Exam1(Ch1, 2).doc_第1页
Exam1(Ch1, 2).doc_第2页
Exam1(Ch1, 2).doc_第3页
Exam1(Ch1, 2).doc_第4页
Exam1(Ch1, 2).doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

Name:_Covers Chapters 1 and 2Introduction to ProgrammingHarbin Normal UniversityInstructor: FullwayPowered By: Y. Daniel LiangPart I: Multiple Choice Questions: (1 pt each)1. aTo add a to b and store result in b, you write (Note: Java is case-sensitive)a.b += a;b.a = b + a;c.b = A + b;d.a += b;2.dTo declare a constant PI, you writea.final static PI = 3.14159;b.final float PI = 3.14159;c.static double PI = 3.14159;d.final double PI = 3.14159;3.cTo declare an int variable x with initial value 200, you x = 200L; x = 200l; x = 200; x = 200.0;4.dTo assign a double variable d to an int variable x, you writea.x = (long)db.x = (int)d;c.x = d;d.x = (float)d;5.dWhich of the Boolean expressions below has incorrect syntax?a.(true) & (3 4)b.!(x 0) & (x 0)c.(x 0) | (x 0)d.(x != 0) | (x = 0)6.bWhich of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?a.1 x 100 & x 0b.(x 1) | (x 0)c.(x 1) & (x x 100) | (x 0)7.aWhich of the following is the correct expression of character a?a.ab.ac.000ad.None of the above.8.aWhich of the following is a constant, according to Java naming conventions?a.MAX_VALUEb.Testc.readd.ReadInt9.aWhich of the following assignment statements is illegal?a.float f = -34; t = 23;c.short s = 10;d.float f = 34.0;10.bA Java statement ends with a _.ma (,)b.semicolon (;)c.period (.)d.closing brace11.bThe assignment operator in Java is _.a.:=b.=c.= = d.-12.dWhich of these data types requires the least amount of memory?a.floatb.doublec.short d.byte13.aWhich of the following operators has the highest precedence?a.castingb.+c.*d./14.eAn int variable can hold _.a.xb.93c.98.3d.truee.a and b15.aWhich of the following assignment statements is correct to assign character 5 to c?a.char c = 5;b.char c = 5;c.char c = 5;d.char c = 344;16.bThe not equal comparison operator in Java is _.a.b.!=c.!= = d.=17.cIf you attempt to add an int, a byte, a long, and a double, the result will be a _ ;c.long;d. double;18.cIf a program compiles fine, but it terminates abnormally at runtime, then the program suffers _.a.a syntax errorb.a runtime errorc.a logic error19.cSuppose x=0 and y=0 what is x after evaluating the expression (y 0) & (1 x+). a.0b.-1c. 120.aSuppose x=0 and y=0 what is x after evaluating the expression (y 0) & (1 x+).a.0b.-1c.121.d Suppose you define a Java class as follows:public class Test In order to compile this class, the class should be stored in a file nameda. Test.classb. Test.docc. Test.txtd. Test.javae. Any name with extension .java22. cThe command to compile a class in the file Test.java isa. java Testb. java Test.javac. javac Test.javad. javac Teste. JAVAC Test.java23. aWhich JDK command is correct to run a Java application in ByteCode.class?a. java ByteCodeb. java ByteCode.classc. javac ByteCode.javad. javac ByteCodee. JAVAC ByteCode24. bWhat is 1 % 2?a. 0b. 1c. 225. cWhat is Welcome + 1 + 1*2?a. Welcome11*2b. Welcome4c. Welcome12d. Welcome326. d What is the printout of the following code:double x = 10.1;int y = (int)x;System.out.println(x is + x + and y is + y);a. x is 10 and y is 10b. x is 10.0 and y is 10.0c. x is 11 and y is 11d. x is 10.1 and y is 10e. x is 10.1 and y is 10.0Part II: Find and correct errors in the following code:(5 pts)public class Test public void Main(String args) /public前要加staitic int j = i + 1;/i要定义且要赋初值,其上一句加上int i=0 int k = MyInput.readDouble()5.5;/k为整形,改为k=5 System.out.println(j is + j + and /转行时应加上加号,改为”and”+”k is” k is + k); Part III: Show the output of the following code:(5 pts)public class Test public static void main(String args) int x1, x2, i, j, k, y, z; float f; x1 = 1; x2 = 1; y = 5 + x1-;6 z = 5 + +x2;7 i = 6 % 4;2 j = 1; j += j + 3;5 k = 25 / 2;12 f = (float)(2 / 5) * k);0.0 System.out.println(x1 is + x1); System.out.println(x2 is + x2); System.out.println(i is + i); System.out.println(j is + j); System.out.println(k is + k); System.out.println(y is + y); System.out.println(z is + z); System.out.println(f is + f); 结果为:x1 is 0x2 is 2i is 2j is 5k is 12y is 6z is 7f is 0.0Part IV: (5 pts) (Dont use the if statement) Write a complete program named Exam1.java. The program reads a double number and checks whether the number is between 1 and 1000. For example, if your input is 5, the output should be: Is the number 5 between 1 and 1000? trueIf your input is 2000, the output should be: Is the number 2000 between 1 and 1000? false答:public class Example1 Pub

温馨提示

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

最新文档

评论

0/150

提交评论