Java 有一种表示逻辑值的简单类型,称为布尔型。它的值只能是真或假这两个值中的一个。它是所有的诸如a下面的程序说明了布尔类型的使用: // Demonstrate boolean values. class BoolTest { public static void main(String args[]) { boolean b.
b = false. System.out.println("b is " b). b = true. System.out.println("b is " b). // a boolean value can control the if statement if(b) System.out.println("This is executed."). b = false. if(b) System.out.println("This is not executed."). // outcome of a relational operator is a boolean value System.out.println("10 > 9 is " (10 > 9)). } }
这个程序的运行结果如下所示: b is false b is true This is executed. 10 > 9 is true