Learning Java. I will make a note so that I can look back on it for review. It's almost my study memo. Please do not excessive expectations.
--What is a boolean value?
There are two values, "true" and "false".
true means true (correct) and false means false (wrong).
The boolean data type is boolean type
.
--Comparison operator
A comparison operator is a symbol for comparing values, and the result of the comparison is a boolean value (true or false).
"X == y" compares whether x and y are the same, and if they are the same, it is true, and if they are different, it is false.
Also, "x! = Y" is the opposite.
Example
// ①「==Output the result of comparing the values using
System.out.println(12 / 4==3);
// ②「!=Output the result of comparing the values using
System.out.println(12 / 4!=3);
//Define a boolean variable bool and set "3"* 9 ==27 ”is substituted
boolean bool = 3 * 9 == 27;
//③ Output the value of the variable bool
System.out.println(bool);
Output result
①true
②false
③true
--Comparison operator/magnitude comparison
The symbols <,> are magnitude comparison symbols that are also used in mathematics.
x <y returns true if x is less than y, false if x is greater than y. x> y is the opposite.
Example
//Compare 8 and 5 and output to be false
System.out.println(8 < 5);
//Compare 3 and 2 and output to be true
System.out.println(3 >= 2);
--Logical operators
A logical operator is a symbol that expresses "and", "or", or "not ~".
-"Katsu" is expressed by && , and "Condition 1 && Condition 2" will be true if "Condition 1 is true and Condition 2 is also true". If either one is false, the result will be false.
Example
System.out.println(8 < 5 && 3 >= 2);
//Output result → false
-"Or" is| |Expressed as "Condition 1||If "condition 2" is "true for either condition 1 or condition 2" The result is true.
Example
System.out.println(8 < 5 || 3 >= 2);
//Output result → true
-"Not ~" can be expressed by using ! . For example,! (X> = 30) is true when "x is not greater than or equal to 30 (that is, less than 30)" and is false when "x is greater than or equal to 30".
Example
System.out.println(!(8 < 5));
//Output result → true
[Java ~ Variable definition, type conversion ~] Study memo
Recommended Posts