已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 天津财经大学《教师职业理念与职业道德规范》2024-2025学年第二学期期末试卷
- 陇南师范高等专科学校《金属凝固原理及技术》2024-2025学年第二学期期末试卷
- 淮南师范学院《V设计》2024-2025学年第二学期期末试卷
- 重庆商务职业学院《嵌入式系统设计B》2024-2025学年第二学期期末试卷
- 四川大学《期货及期权投资实务》2024-2025学年第二学期期末试卷
- 2026重庆荣昌区市场监督管理局招聘1人考试参考题库及答案解析
- 2026安徽合肥一六八玫瑰园南校教育集团临湖学校教师招聘考试参考试题及答案解析
- 2026湖北大学后勤集团绿化环卫中心招聘8人笔试备考题库及答案解析
- 2026福建莆田城厢区顶墩实验学校初中编外教师招聘笔试备考试题及答案解析
- 2026航天中心医院第一批护理招聘24人考试参考题库及答案解析
- 2026河南郑州建设集团所属公司社会招聘工作人员44名笔试备考题库及答案解析
- 菏泽医专综评试题及答案
- GB/T 9944-2025不锈钢丝绳
- 高二数学开学第一课(高教版2023修订版)-【开学第一课】2025年春季中职开学指南之爱上数学课
- 大学生创新创业基础(创新创业课程)完整全套教学课件
- 罗氏治疗药物监测(TDM)概述及竞争分析课件
- 特种设备作业人员补(换)证申请表
- 四川大学办公用房管理实施细则
- 高中数学必修二 6.2.1 平面向量的加法运算
- 大众文化导论完整版课件最全电子教案
- 兽药GSP认证材料样表
评论
0/150
提交评论