0

For what purpose we use boolean

I want to be app developer

7th Feb 2017, 5:41 AM
Veer Metri
Veer Metri - avatar
5 Respostas
+ 8
I don't know Java, but: if switch is true: turn on light if switch is false: turn off light
7th Feb 2017, 5:49 AM
Ahri Fox
Ahri Fox - avatar
+ 7
you use boolean like an off and on switch
7th Feb 2017, 5:46 AM
Ahri Fox
Ahri Fox - avatar
+ 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.
7th Feb 2017, 5:59 AM
Peter
+ 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.
7th Feb 2017, 6:08 AM
Varun Moghe
Varun Moghe - avatar
0
Can you give me example
7th Feb 2017, 5:47 AM
Veer Metri
Veer Metri - avatar