首页 复习题答案05review

复习题答案05review

举报
开通vip

复习题答案05reviewChapter 5 Methods 1. At least three benefits: (1) Reuse code; (2) Reduce complexity; (3) Easy to maintain. See the Sections 5.2 and 5.3 on how to declare and invoke methods. What is the subtle difference between “defining a method” and “declaring a variabl...

复习题答案05review
Chapter 5 Methods 1. At least three benefits: (1) Reuse code; (2) Reduce complexity; (3) Easy to maintain. See the Sections 5.2 and 5.3 on how to declare and invoke methods. What is the subtle difference between “defining a method” and “declaring a variable”? A declaration usually involves allocating memory to store a variable, but a definition doesn’t. 2. void 3. Yes. return (num1 > num2) ? num1 : num2; 4. True: a call to a method with a void return type is always a statement itself. False: a call to a value-returning method is always a component of an expression. 5. A syntax error occurs if a return statement is not used to return a value in a value-returning method. You can have a return statement in a void method, which simply exits the method. But a return statement cannot return a value such as return x + y in a void method. 6. See Section 5.2. 7. Computing a sales commission given the sales amount and the commission rate public static double getCommission(double salesAmount, double commissionRate) Printing a calendar for a month public static void printCalendar(int month, int year) Computing a square root public static double sqrt(double value) Testing whether a number is even and return true if it is public static boolean isEven(int value) Printing a message for a specified number of times public static void printMessage(String message, int times) Computing the monthly payment, given the loan amount, number of years, and annual interest rate. public static double monthlyPayment(double loan, int numberOfYears, double annualInterestRate) Finding the corresponding uppercase letter given a lowercase letter. public static char getUpperCase(char letter) 8. Line 2: method1 is not defined correctly. It does not have a return type or void. Line 2: type int should be declared for parameter m. Line 7: parameter type for n should be double to match method2(3.4). Line 11: if (n<0) should be removed in method, otherwise a compile error is reported. 9. public class Test { public static double xMethod(double i, double j) { while (i
本文档为【复习题答案05review】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_645986
暂无简介~
格式:doc
大小:86KB
软件:Word
页数:0
分类:互联网
上传时间:2018-09-09
浏览量:1