mardi 22 octobre 2019

How can I display a number if it's divisible by two numbers but not a third in java?

How can I display a number if it's divisible by two numbers but not a third in java? I'm not sure if I got the last operator right in relation to this part || ((a % 4) == 0)) of the code below.

int a = 15;

if ((( a % 5) == 0) || ((a % 10) == 0) || ((a % 4) == 0)) {
    System.out.println("Number entered is divisible by 5 and 10 but not 4");
} else {
    System.out.println("ERROR");
}

Aucun commentaire:

Enregistrer un commentaire