[Java ~ Boolean value ~] Study memo (2)

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.

Boolean value

--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


Past posts

[Java ~ Variable definition, type conversion ~] Study memo

Recommended Posts

[Java ~ Boolean value ~] Study memo (2)
[Java ~ Method ~] Study memo (5)
[Java ~ Array ~] Study memo 4
Java Silver Study Method Memo
Java study memo 2 with Progate
Java memo
[Study session memo] Java Day Tokyo 2017
Let's study Java
java, maven memo
[Java ~ Variable definition, type conversion ~] Study memo
Java SE 7 memo
java anything memo 2
[Java] Study notes
Java 8 study (repeatable)
Java study memorandum
[Java ~ Conditional branching / Iterative processing ~] Study memo (3)
Study Java Silver 1
[Java ~ Classes and External Libraries ~] Study Memo (6)
Java specification memo
Java pattern memo
Study session memo: Kansai Java Engineers Association 8/5 --Selenium
Java development environment memo
Java Silver Study Day 1
java basic knowledge memo
Java learning memo (method)
Java Kuche Day memo
java se 8 programmer Ⅰ memo
Java paid private memo
Dot installation study memo 01
Java study # 1 (typical type)
Java learning memo (basic)
java lambda expression memo
(Memo) Java for statement
My Study Note (Java)
Java lambda expression [memo]
Java learning memo (interface)
[Java] Implicit inheritance memo
Java learning memo (inheritance)
java competitive programming memo
[Memo] Java Linked List
Try Java return value
Study Java # 2 (\ mark and operator)
Java (WebSphere Application Server) memo [1]
[Java] Variable name naming memo
Play Framework Study Memo Database ①
Java learning memo (data type)
Study java arrays, lists, maps
Java memo (standard class) length
Create a java method [Memo] [java11]
Java Silver exam preparation memo
Introduction to JUnit (study memo)
Study session memo: Kansai Java Engineers Association [Osaka] 7/12 --Cloud Native
Java learning memo (logical operator)
Java study # 7 (branch syntax type)
Java learning memo (abstract class)
[Java] Date Related Term Memo
Ruby study memo (recursive function)
Study Java with Progate Note 1
[Ruby ~ Iterative processing ~] Study memo 4
What are Java metrics? _Memo_20200818
Java HashMap, entrySet [Personal memo]