Berikut merupakan contoh program operator logika dengan menggunakan java.
class DemoOperatorLogika {
public static void main(String[] args) {
System.out.println("Operasi AND");
System.out.println("true && true = " + (true && true));
System.out.println("true && false = " + (true && false));
System.out.println("false && true = " + (false && true));
System.out.println("false && false = " + (false && false));
System.out.println("\nOperasi OR");
System.out.println("true || true = " + (true || true));
System.out.println("true || false = " + (true || false));
System.out.println("false || true = " + (false || true));
System.out.println("false || false = " + (false || false));
System.out.println("\nOperasi XOR");
System.out.println("true ^ true = " + (true ^ true));
System.out.println("true ^ false = " + (true ^ false));
System.out.println("false ^ true = " + (false ^ true));
System.out.println("false ^ false = " + (false ^ false));
System.out.println("\nOperasi NOT");
System.out.println("!true = " + (!true));
System.out.println("!false = " + (!false));
}
}
public static void main(String[] args) {
System.out.println("Operasi AND");
System.out.println("true && true = " + (true && true));
System.out.println("true && false = " + (true && false));
System.out.println("false && true = " + (false && true));
System.out.println("false && false = " + (false && false));
System.out.println("\nOperasi OR");
System.out.println("true || true = " + (true || true));
System.out.println("true || false = " + (true || false));
System.out.println("false || true = " + (false || true));
System.out.println("false || false = " + (false || false));
System.out.println("\nOperasi XOR");
System.out.println("true ^ true = " + (true ^ true));
System.out.println("true ^ false = " + (true ^ false));
System.out.println("false ^ true = " + (false ^ true));
System.out.println("false ^ false = " + (false ^ false));
System.out.println("\nOperasi NOT");
System.out.println("!true = " + (!true));
System.out.println("!false = " + (!false));
}
}
Operator Logika dengan Java
Reviewed by ReyGumay
on
November 19, 2016
Rating:
No comments: