Menggunakan Operator Logika

Assalamualaikum, ..
Kali ini saya akan membagikan cara menggunakan operator logika pada pemrograman java, . .

import java.util.Scanner;

public class UseLogicalOperator {

public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);

System.out.print("Enter a number: ");
int num = s.nextInt();

System.out.println(num + " is divisible by 5 and 6? " +
(num % 5 == 0 && num % 6 == 0));
System.out.println(num + " is divisible by 5 or 6? " +
(num % 5 != 0 || num % 6 != 0));
System.out.println(num + " is divisible by 5 or 6, but not both? " +
(num % 5 != 0 ^ num % 6 != 0));
}

}

Semoga bermanfaat, . .

Subscribe to receive free email updates:

0 Response to "Menggunakan Operator Logika"

Post a Comment