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.

  • 相关阅读:
    HDU ACM 1020 Encoding
    HDU ACM 1019 Least Common Multiple
    HDU ACM 1009 FatMouse' Trade
    HDU ACM 1032 The 3n + 1 problem
    HD ACM 1061 Rightmost Digit
    UVa 401 Palindromes
    UVa 489 Hangman Judge
    HDU ACM 1071 The area
    5/25
    受涼6/8
  • 原文地址:https://www.cnblogs.com/allenblogs/p/2239228.html
Copyright © 2011-2022 走看看