what is boolean in java plz make me understand in easy way | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 1

what is boolean in java plz make me understand in easy way

what is boolean in java plz make me understand in easy way

24th Nov 2017, 3:49 PM
Lucky
Lucky - avatar
7 Respostas
0
plz tell
24th Nov 2017, 3:49 PM
Lucky
Lucky - avatar
0
Boolean variables can have a value of true or false, nothing else. they are used to describe the state of an expression, whether its true or false
24th Nov 2017, 3:55 PM
Dmitrii
Dmitrii - avatar
0
explain me plz by giving an example plz
24th Nov 2017, 3:57 PM
Lucky
Lucky - avatar
0
x=1; if (x>0) the expression inside the parenthesis is true. the other value that this expression can take is false. you can make it false by typing (!x>0)
24th Nov 2017, 4:05 PM
Dmitrii
Dmitrii - avatar
0
A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is a variable type for Boolean values: boolean user = true; So instead of typing int or double or string, you just type boolean (with a lower case "b"). After the name of you variable, you can assign a value of either true or false. Notice that the assignment operator is a single equals sign ( = ). If you want to check if a variable "has a value of" something, you need two equal signs ( = =). Try this simple code: boolean user = true; if ( user == true) { System.out.println("it's true"); } else { System.out.println("it's false"); } So the first IF Statement checks if the user variable has a value of true. The else part checks if it is false. You don't need to say "else if ( user = = false)". After all, if something is not true then it's false. So you can just use else: there's only two choices with boolean values. The only other conditional operator on our lists is the NOT operator. You can use this with boolean values. Have a look at the following code: boolean user = true; if ( !user ) { System.out.println("it's flase"); } else { System.out.println("it's true"); } It's almost the same as the other boolean code, except for this line: if ( !user ) { This time, we have our NOT operator before the user variable. The NOT operator is a single exclamation mark ( ! ) and it goes before the variable you're tying to test. It's testing for negation, which means that it's testing for the opposite of what the value actually is. Because the user variable is set to true then !user will test for false values. If user was set to false then !user would test for true values. Think of it like this: if something is NOT true then what is it? Or if it's NOT false then what?
24th Nov 2017, 4:05 PM
LISANGOLA BONDJALI CHRISTIAN
LISANGOLA BONDJALI CHRISTIAN - avatar
0
what is this
24th Nov 2017, 4:06 PM
Lucky
Lucky - avatar
0
where is boolean statement
24th Nov 2017, 4:06 PM
Lucky
Lucky - avatar