0
For what purpose we use boolean
I want to be app developer
5 Réponses
+ 8
I don't know Java, but:
if switch is true:
turn on light
if switch is false:
turn off light
+ 7
you use boolean like an off and on switch
+ 1
for example to make a check for something:
if (someoneisinroom()){
light.on();
}else{
light.off();
}
where someoneisinroom() method would have been made before that checks if someone walks in the room and return true if it did.
static boolean someoneisinroom(){
boolean b = false;
if (person is in the room){
b = true;
}
return b;
}
another example is i used this in my code to to calculate days to make it check wether a year is a leapyear or not.
+ 1
The boolean datatype is used to determine the output of a conditional statement. The if statement in Java returns the boolean value true or false depending on the output of the condition specified between the brackets. The boolean values can also be used for setting flags in the program.
0
Can you give me example