zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    《架构之美》阅读笔记六
    《架构之美》阅读笔记五
    软件工程——个人总结
    软件工程——团队作业4
    软件工程——团队答辩
    软件工程-团队作业3
    软件工程——团队作业2
    软件工程-团队作业1
    软件工程第二次作业——结对编程
    软件工程第一次作业补充
  • 原文地址:https://www.cnblogs.com/allenblogs/p/2239228.html
Copyright © 2011-2022 走看看