Week 6Methods课件.ppt

  1. 1、本文档共13页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
In this chapter you will learn: How static methods and fields are associated with an entire class rather than specific instances of the class. To use common Math methods available in the Java API. To understand the mechanisms for passing information between methods. How to use random-number generation to implement game-playing applications. Including the declaration import java.util.Scanner; allows the programmer to use Scanner instead of java.util.Scanner Java API documentation /j2se/5.0/docs/api/index.html Overview of packages in JDK 5.0 /j2se/5.0/docs/api/overview-summary.html To promote software reusability, every method should be limited to performing a single, well-defined task, and the name of the method should express that task effectively. Such methods make programs easier to write, debug, maintain and modify. A small method that performs one task is easier to test and debug than a larger method that performs many tasks. Class Math is part of the java.lang package, which is implicitly imported by the compiler, so it is not necessary to import class Math to use its methods. -Three ways to call a method: Use a method name by itself to call another method of the same class Use a variable containing a reference to an object, followed by a dot (.) and the method name to call a method of the referenced object Use the class name and a dot (.) to call a static method of a class - static methods cannot call non-static methods of the same class directly It is a syntax error to break a String literal across multiple lines in a program. If a String does not fit on one line, split the String into several smaller Strings and use concatenation to form the desired String. Confusing the + operator used for string concatenation with the + operator used for addition can lead to strange results. Java evaluates the operands of an operator from left to right. For example, if integer variable y has the value 5, the expression y + 2 = + y + 2 results in the string y + 2 = 52,

文档评论(0)

liuxiaoyu98 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档