Professional Documents
Culture Documents
Pertemuan 5 - OPERATOR
Pertemuan 5 - OPERATOR
Pertemuan 5 - OPERATOR
* |
Algoritma
-
Pemrograman
+ OPERATOR >=
< <=
= !
Operators are used to perform operations on variables
and values
• Example “+” operator is often used to add together two values, it can
also be used to add together a variable and a value, or a variable and
another variable:
Java divides the operators into the following
groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Bitwise operators
Arithmetic Operators
+ Addition Adds together two values
- Subtraction Subtracts one value from another
X = 10;
Java Assignment Operators
Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
Java Comparison Operators
Operator Name
== Equal to
Comparison != Not equal
operators are used > Greater than
to compare two < Less than
values: >= Greater than or
equal to
<= Less than or equal to
Java Logical Operators
Operator Name Description
Logical operators are used to && Logical and Returns true if both
statements are true
determine the logic between || Logical or Returns true if one of the
statements is true
variables or values: ! Logical not Reverse the result, returns
false if the result is true
+