Sunteți pe pagina 1din 2

Example 1:

LOGICAL NOT (!)


OPERATOR In this statement it is said that the value of variable b is less
The NOT logic operation returns true if its input is false, and than the value of variable a OR the value of variable b is not
00
false if its input is true. equal to the value of variable a is true. Even the first part of
The NOT operation is usually written as ! (an exclamation the statement is wrong. The statement will be true because the
point). OR logic operator’s job is to return true if any of its inputs
are true. And if all of the inputs are false, the output is also
false.

LOGICAL AND (&&)

True
OPERATOR
-The AND logic operation returns true only if all of its inputs
Concatenation in Java is the operation of joining two strings are true. If any the output is false, the output is also false.
together. -The AND operation is usually written as &&
Example 2:
You can join strings using the addition (+) (two ampersand).
It shows here that if you put a
number (int) that is less than
the given number [ if ( ) ] the
system will print out the word
In this statement it is said that inside the parenthesis.
variable a is NOT greater than variable b is true. Because the
In this statement it is said the the value of variable a is less
value of variable a is equal to 9 and the value of variable b is
than the value of variable b AND the value of variable b is
equal to 20. So if you substitute 9 to variable a and substitute
greater than the value of variable a is true. Because the first
20 to variable b. The statement will be “9 is NOT greater than
and second part is correct. And the value of variable a in this
20” that’s correct because the job of NOT operator is to return
statement is 9 and the value of variable b in this statement is
true if its input is false, and false if its input is true.
20. So if you substitute 9 to variable a and substitute the 20 to
variable b. The statement will be 9 is less than 20 which is true
LOGICAL OR (||)
AND 20 is greater than 9 which is also true.

False
OPERATOR
-The OR logic operation returns true if any of its inputs are
Condition for Decisions
true. If all of the inputs are false, the output is also false.
It shows here that if you put a number (int) that is equal to
-The OR operation is usually written as || (two vertical bars).
the given number [ If ( ) ] the system will print out
What if the given number in “int” is bigger than the “if”?
the word inside the parenthesis.
If and else statement

False

As you can see it is false It shows here that our operator is “>=” (Greater than or equal
To make it true, we have to to). So if we put greater or exact number (which is 90 in this
change the operator example) the system will show, “You get a piece of candy” and
”You are awesome!”).

True

If you put lower than the given number (which is 90) the system
will show, “Better luck next time kid.” (else)

S-ar putea să vă placă și