What is boolean and how can it be used | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is boolean and how can it be used

10th Jan 2022, 8:16 PM
Loo Student
4 Answers
10th Jan 2022, 8:34 PM
Coding Cat
Coding Cat - avatar
+ 3
It is the result of an expression that evaluates to true (1) or false (0). It is also true, pun intended, that if you search here in Discuss for boolean you will find the answer to the question you asked.
10th Jan 2022, 8:31 PM
Paul K Sadler
Paul K Sadler - avatar
+ 2
Hi Loo Student A Google search would’ve give you the same answer. Booleans store two possible values. Usually either true or false. An example for the usage of a boolean would be.. /* asking if someone is permitted to do something… */ boolean permissions = true; if ( permissions == true) { 
System.out.println("User is permitted!"); 
} 
else { 
System.out.println("User doesn’t have the necessary permissions!"); 
}
10th Jan 2022, 8:34 PM
Alex Nicolas Kessi
Alex Nicolas Kessi - avatar
0
It is used mostly to execute code where particular conditions are met by the input or parameters passed to a function. For example, if you pass a phone number instead of an email address in a web form, the validity checker returns false and the code to submit your input is not executed.
11th Jan 2022, 8:50 PM
SAM
SAM - avatar