Java > Warmup-1 > or35 (CodingBat Solution)

Problem:

Return true if the given non-negative number is a multiple of 3 or a multiple of 5. Use the % "mod" operator -- see Introduction to Mod

or35(3) → true
or35(10) → true
or35(8) → false


Solution:

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

2 comments:

  1. Just learned ternary lol

    public boolean or35(int n) {

    boolean or = (n%3==0 || n%5==0) ? true : false;

    return or;

    }

    ReplyDelete