文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 《Java语言程序设计:基础篇》课后复习题答案-第五章
侵权投诉

《Java语言程序设计:基础篇》课后复习题答案-第五章

《Java语言程序设计:基础篇》课后复习题答案

Chapter5Methods

1.Atleastthreebenefits:(1)Reusecode;(2)Reducecomplexity;(3)Easytomaintain.SeetheSections5.2and5.3onhowtodeclareandinvokemethods.Whatisthesubtledifferencebetween“definingamethod”and

“declaringavariable”?Adeclarationusuallyinvolvesallocatingmemorytostoreavariable,butadefinitiondoesn’t.2.3.4.5.

void

Yes.return(num1>num2)?num1:num2;

True:acalltoamethodwithavoidreturntypeisalwaysastatementitself.

False:acalltoavalue-returningmethodisalwaysacomponentofanexpression.Asyntaxerroroccursifareturnstatementisnotusedtoreturnavalueinavalue-returningmethod.Youcanhaveareturnstatementinavoidmethod,whichsimplyexitsthemethod.Butareturnstatementcannotreturnavaluesuchasreturnx+yinavoidmethod.SeeSection5.2.

ComputingasalescommissiongiventhesalesamountandthecommissionratepublicstaticdoublegetCommission(doublesalesAmount,doublecommissionRate)

Printingacalendarforamonth

publicstaticvoidprintCalendar(intmonth,intyear)Computingasquareroot

publicstaticdoublesqrt(doublevalue)

TestingwhetheranumberisevenandreturntrueifitispublicstaticbooleanisEven(intvalue)

Printingamessageforaspecifiednumberoftimes

publicstaticvoidprintMessage(Stringmessage,inttimes)

Computingthemonthlypayment,giventheloanamount,numberofyears,andannualinterestrate.

publicstaticdoublemonthlyPayment(doubleloan,intnumberOfYears,doubleannualInterestRate)Findingthecorrespondinguppercaselettergivenalowercaseletter.

6.7.

第1页

TOP相关主题

你可能喜欢

  • java基础测试题
  • java程序设计
  • java考试题
  • java模拟题
  • java应用程序
  • JAVA基础教程

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email