Operator Pada Pemrograman

6:38:00 PM


            Tujuan

  •     Mengenal dan memahami tipe-tipe operator pada JAVA
  •   Mengembangkan program Java sederhana menggunakan konsep yang dipelajari pada bab ini

Pokok bahasan
  •   Operator Aritmatika
  •   Operator Increment dan Decrement
  •   Operator Relasi
  •   Operator Logika
  •   Operator Kondisi

                        Operator Aritmatika
Operator
Use
Description
+
op1 + op2
Adds op1 and op2
*
op1 * op2
Multiplies op1 by op2
/
op1 / op2
Divides op1 by op2
%
op1 % op2
Computes the remainder of dividing op1 by op2
-
op1 – op2
Subtracts op2 from op1

Operator Increment dan Decrement
Operator
Use
Description
++
op++
Increments op by 1; evaluates to the value of op before it was incremented
++
++op
Increments op by 1’ evaluates to the value of op before it was decremented
--
op--
Decrements op by 1; evaluates to the value of op before it was decremented
--
--op
Decrements op by 1; evaluates to the value of op after it was decremented

Operator Relasi
Operator relational digunakan untuk membandingkan  beberapa nilai dan menuntaskan hubungan antara nilai-nilai tersebut

Output dari perbandingan tersebut adalah nilai Boolean antara true atau false
Operator
Use
Description
op1 > op2
Op1 is greater than op2
>=
op1 >= op2
Op1 is greater than or equal to op2
op1 < op2
Op1 is less than op2
<=
op1<= op2
Op1 is less than or equel to op2
==
op1== op2
Op1 and op2 are equal
!=
op1!= op2
Op1 and op2 are not equal

                       

                        Operator Logika
  •  &&(logical) dan &(Boolean logical) AND
  •  ||(logical) dan |(Boolean logical) inclusive OR
  •  ^(Boolean logical exclusive OR)
  •  !(logical NOT)

ü      &&(logical) dan &(Boolean logical) AND
X1
X2
Result
True
True
True
True
False
False
False
True
False
False
False
False

ü      ||(logical) dan |(Boolean logical) inclusive OR
X1
X2
Result
True
True
True
True
False
True
False
True
True
False
False
False

ü       ^(Boolean logical exclusive OR)
X1
X2
Result
True
True
False
True
False
True
False
True
True
False
False
False


ü      !(logical NOT)
X1
Result
True
False
False
True

Operator kondisi
Exp1?Exp2:Exp3
Exp1 = Kondisi
Exp2 = Statement yang berlaku jika kondisi bernilai benar
Exp3 = Statement yang berlaku jika kondisi bernilai salah

You Might Also Like

0 comments