Coding Bat – or35

This exercise requires that the program return the value of true if the given number is evenly divisible by either 3 or 5. The instructions encourage us to utilize modulus division to solve this problem.

As a reminder, modulus division is the “remainder” after you solve a division problem.

Here is the code that you start with:

public boolean or35(int n) {
 
}

As you can see, we have a single integer variable named “n”.

public boolean or35(int n) {
  return (n % 3 == 0) || (n % 5 == 0);
}

The provided solution does not utilize variables beyond the single provided n.

public boolean or35(int n) {
 double modFive = n % 5;
 double modThree = n % 3;
 if (modFive == 0 || modThree == 0){
 return true;
 }
 return false;
}

An alternative solution could use variables for the division and inside the conditional statements.

Leave a Reply

Your email address will not be published. Required fields are marked *