Very often in programming, you will need a data type that can only have one of two values, like:
For this, Java has a boolean
data type, which can only take the values true
or false
:
boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun); // Outputs true
System.out.println(isFishTasty); // Outputs false
Boolean values are mostly used for conditional testing.
You will learn much more about booleans and conditions later in this tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!