下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.CSCE 145: Test 1 Key, Spring 2013Questions 1 to 8 are worth 8 points each. Questions 9 to 12 are worth 9 points each.1. What would be the exact result of executing the following statements? int shoeSize = 9; String brand = “Manolo”; int total = shoeSize * 2; /9 System.out.println(“I want “ +brand +
2、“ shoes”); System.out.println(“What size?”); System.out.print(total +”, ”); System.out.println(shoeSize +“ for each foot. HaHa.”);I want Manolo shoesWhat size?18, 9 for each foot. HaHa.2. Suppose the class Dog has the boolean instance variable wagsTail and the setter method setWagsTail with one para
3、meter: a boolean. fido is an object in the class Dog. Write the statement that would cause the wagsTail instance variable for fido to be set to true.fido.setWagsTail(true);3. Assume that int x = 3, int y = 2, and int z = 6. What would be the value of variable b after the following statement is execu
4、ted? boolean b = (x < y) && (x * y / z > z) | (x + y <= z);/ F && F | T => F | T => T _true_4. What would be the value of variable c4 after the following statement is executed? int c4 = 2 * 5 + 4 3 * 2; _8_5. An apple grower has crates that hold 24 apples each. Assume
5、the grower picks n apples. Finish the following Java expression that would find how many apples would be in the last partially filled crate. For example, if he picked 51 apples, he could fill two crates and would have 3 apples left over. int leftOverApples = n % 24;6. What would be the value of vari
6、able total after the following statements are executed? int total = 4; total+; total = total * 5;_25_7. The following code uses a for-loop to compute the value of this sum: n=599n (n-1)int sum = 0;for (int n = 5; n <= 99; n+) sum = sum + n * (n 1);Convert it to an equivalent sum =
7、0;int n = 5;while (n <= 99) sum = sum + n * (n 1); n+;8. Write an int method summation() that has no parameters and returns the value of the summation in problem #12 above. You can use either a for-loop or a while-loop.public int summation() int sum = 0; for (int n = 5; n <= 99; n+) sum = sum
8、+ n * (n 1); return sum;9. What is the output of the following code segment? int i = 5; int j = 7; int k = 6; if (i > j) | (k < 5) System.out.println(“yes 1”); else System.out.println(“no 2”); if (i < j) && (k > 5) System.out.println(“yes 3”); else System.out.println(“no 4”);no 2
9、yes 310. Write the three Java expressions that are equivalent to the following three mathematical formulas: a2+b2 (t2 + 5 t 4) Math.sqrt(a*a + b*b) * (t*t + 5*t 4)(t-5)(t+8)/(2d+e) (t 5) * (t + 8) / (2 * d + e)-b+b2-4ac2a (-b + Math.sqrt(b*b 4*a*c) / (2*a)11. What is the output of the following code
10、 segment? String player1 = “rock”; String player2 = “paper”; if (player1.equals(player2) System.out.println(“Tie!”); else if (player1.equals(“rock”) if (player2.equals(“paper”) System.out.println(“Player 1 loses”); else System.out.println(“Player 1 wins”); else if (player1.equals(“paper”) if (player
11、2.equals(“rock”) System.out.println(“Player 1 wins”); else System.out.println(“Player 1 loses”); else /player1 s if (player2.equals(“rock”) System.out.println(“Player 1 loses”); else System.out.println(“Player 1 wins”); System.out.println(“Player 1 quits”);Player 1 losesPlayer 1 quits16512. Given th
12、e following definition for the classes Room and House, write a method in the House class called getSquareFootage that returns the total square footage of all three rooms in an instance of a House. public class Room private String type; / a variable for storing the type of a / Room, such as “kitchen,” or “bedroom” private int length; / the length of the Room in feet private int width; / the width of the Room in feet /Assume there are getters and setters for the 3 instance /variables above, such as getWidth() and getLength() public class House private Room br1; / bedroom #1 private
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 病房医院感染管理消毒隔离制度
- 质量月活动总结汇报报告
- 《一起做动画》教学设计-2026-2027学年沪书画版(五四学制)(新版)初中美术七年级上册
- 2026年上半年保教知识与能力真题与答案
- 2026年下半年全国教师资格证考试中学《综合素质》真题及答案
- 高中地理教资面试结构化答辩题库
- 初中音乐教资面试欣赏知识易错题题库
- 电梯日常巡检流程SOP-含巡检表和异常记录
- 辽宁沈阳杏坛中学2026−2027学年上学期七年级七年级综合素质评价 数学试题(含答案)
- 2026年注册安全工程师考试冲刺押题安全生产法规解读
- 造船厂安全制度
- 2026中国废旧木材回收利用行业分析及投资可行性研究报告
- 26秋教科版三年级上册科学全册必背知识点新教材含答案
- 4.RBT 089-2022绿色供应链管理手册
- (2025)肺移植术后慢性移植肺失功专家共识
- 2026-2030中国矿山生态修复行业前景规划及投资潜力分析报告
- YY/T 0148-2006医用胶带 通用要求
- WS/T 453-2014丙型病毒性肝炎筛查及管理
- GB/T 39673.52-2020住宅和楼宇电子系统(HBES)及楼宇自动化和控制系统(BACS)第52部分:用于住宅、商业和轻工业环境下的HBES和BACS的EMC要求
- GB/T 3323.1-2019焊缝无损检测射线检测第1部分:X和伽玛射线的胶片技术
- 马工程教材《公共财政概论》PPT-绪论
评论
0/150
提交评论