1.Operator Penugasan
public static void main(String[]args){
int a = 20;
System.out.println(a+=5); //20+5 = 25
int b = 7;
System.out.println(b-=5); //7-5 = 2
int c = 9;
System.out.println(c*=3); //9*3 = 27
int d = 10;
System.out.println(d/=3); //10/3 = 3.333
int e = 10;
System.out.println(e%=3); //10%3 = 1
}
}
Maka akan menampilkan hasil:
run:
25
2
27
3
1
BUILD SUCCESSFUL (total time: 0 seconds)
2. Operator Pembanding
public static void main(String[]args) {
int A = 10;
int B = 7;
boolean hasil;
hasil = A > B;
System.out.println(hasil);
hasil = A < B;
System.out.println(hasil);
hasil = A >= B;
System.out.println(hasil);
hasil = A == B;
System.out.println(hasil);
hasil = A != B;
System.out.println(hasil);
}
}
Maka akan menampilkan hasil:
run
true
false
true
false
true
BUILD SUCCESSFUL (total time: 0 seconds)
3.Operator Logika
1.
public static void main(String[] args){
int A =75;
int B =85;
int C =90;
boolean a = A > B && B < C;
boolean b = A < B && B < C;
System.out.println(a);
System.out.println(b);
}
}
HASILNYA:
run:
false
true
BUILD SUCCESSFUL (total time: 0 seconds)
2.public static void main(String[] args){
int A = 70;
int B = 80;
int C = 90;
boolean a = A > B && B < C || C < B;
boolean b = A < B || B < C && C < B;
System.out.println(a);
System.out.println(b);
}
}
HASILNYA:
run:
false
true
BUILD SUCCESSFUL (total time: 0 seconds)
3. public static void main(String[] args){
int A = 70;
int B = 90;
boolean a = A > B;
System.out.println(!a);
}
}
HASILNYA:
run:
true
BUILD SUCCESSFUL (total time: 0 seconds)
Tidak ada komentar:
Posting Komentar