Think in java 答案_Chapter 2_Exercise 5

来源:互联网 发布:表情包 面具 淘宝 编辑:程序博客网 时间:2024/04/28 03:25

阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx

/****************** Exercise 5 ******************
* Write a program that includes and calls the
* storage() method defined as a code fragment in
* this chapter.
***********************************************/

public class E05_Storage {
  String s = "Hello, World!";
  int storage(String s) {
    return s.length() * 2;
  }
  void print() {
    System.out.println(
      "storage(s) = " + storage(s));
  }
  public static void main(String[] args) {
    E05_Storage st = new E05_Storage();
    st.print();
  }
}  

/** You could have also made storage( ) a static method and just called it from main( ).*/

//+M java E05_Storage

原创粉丝点击