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

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact