CS106A 编程方法学(五)


看到 Mehran Sahami 把变量 variable 比做盒子 box,真是让人开心,因为我也是这么想的。

一个变量有三个要素:名字 name,类型 type 和 值 value。

编程语言里面的关键字也不是 key word 而是 reserve word。

Java 中的原类型 primitive type

整型 int (integer),取值范围 minus 2 billion to 2 billion,整型一般用来说明:how many kind value counting

双精度浮点型 double,real-value number,用来说明:how much there is,no next value


give variables an initial value when it make sense it is also good software engineering.

在写 C# 程序的时候,遇到整型变量,我还是比较习惯使用默认值“0”;字符型的变量,有时候我会赋初始值 string.Empty。

type name = value;

variable = expression;

You can say, give me a variable that is a box, and the type that the box holds is an object that’s the type of some class, so all classes can actually be used as type means.

the object is receiver who’s receiving or being told to do something.

the name of the variable is the receiver and the method that’s being called is the message.

取余运算符 remainder operator  % : 7 % 2 = 1

posted on 2012-03-11 20:16 zhaorui 阅读(...) 评论(...) 编辑 收藏




  • 随笔 - 321
  • 文章 - 7
  • 评论 - 156
  • 引用 - 2