Determining if a number is either a multiple of ten or within a particular set of ranges

For the first one, to check if a number is a multiple of use:

if (num % 10 == 0) // It's divisible by 10

For the second one:

if(((num - 1) / 10) % 2 == 1 && num <= 100)

But that’s rather dense, and you might be better off just listing the options explicitly.


Now that you’ve given a better idea of what you are doing, I’d write the second one as:

   int getRow(int num) {
      return (num - 1) / 10;
   }

   if (getRow(num) % 2 == 0) {
   }

It’s the same logic, but by using the function we get a clearer idea of what it means.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)