Life is short, you need Python

Java初体验之bool

Both the C++ and Java languages have boolean types, which are called bool and
boolean, respectively. Although these types have similar names and uses, they are
represented in completely different formats.

Later implementations of C++ include a new bool type, whose values are
represented by the new keywords true and false. In actuality, the bool type is
represented as an int, and true and false correspond to 1 and 0 respectively.
You can use int values and bool values interchangeably; 0 is converted to false,
and all other number values are converted to true.

The Java language defines the boolean type, whose values are represented by the
true and false literals, which are the only valid values of the Java boolean type.
Unlike the C++ bool type, the boolean type cannot be converted to or from the
int type. In fact, the only valid conversion for a boolean value is to or from another
boolean value.

In Java programs, you cannot use int type values or expressions in place of
boolean type values or expressions. For example, if you use an int in an if
statement, which evaluates a boolean expression, the Java compiler will generate
an error. This is a major change from C and C++, both of which use int values in
logical expressions.

posted @ 2011-11-07 14:30  runfox545  阅读(2857)  评论(0编辑  收藏  举报
白月黑羽 Python教程 白月黑羽Python