+ 3
What is the use of Boolean in Java?
3 Respostas
+ 2
It is a datatype to check informations, that can only have 2 different values.
You can get booleans, when you compare values.
5 < 7 --> 5 is less than 7 --> true
6 == 4 --> 6 is equal to 4 --> false
3 >= 3 --> 3 is great than or equal to 3 --> true
This is very close to real life conditions. In real lif you could say "If I have atleast 300€, I can buy a new bicycle.".
In programming world, it would be something like this:
int money = 400;
if (money >= 300) {
System.out.println("I can buy a new bicycle.");
}
"I can buy a new bicycle." would be printed if money >= 300 was true, otherwise it would be skipped.
+ 3
True or false
+ 3
Hmm, you know, boolean is a kind of logic which is used in languages like java. You may know boolean algebra. But, in java, boolean is used as logic to determine and compare where the given inputs are either true or false.