0

I have Firebase database where a number value is stored for a specific user. I want to show an advert when the value reaches multiples of 5, starting at 0.

I can get it to call the method from for the first multiple of 5 using an if statement like this

  if (ads < 5 && dls > 5) {
        Toast.makeText(c,"Testing it worked here",Toast.LENGTH_LONG).show();

How can I edit this so it calls it at 10, 15, 20, 25 and so on?

markharrop
  • 866
  • 1
  • 9
  • 30

2 Answers2

0

Try the modulus operation.

if (dls % 5 == 0) {
    Toast.makeText(c,"Testing it worked here",Toast.LENGTH_LONG).show();
Troy Poulter
  • 677
  • 1
  • 8
  • 29
  • [this link](https://stackoverflow.com/a/2664304/7788355) explains more about the modulus operation if interested :) – Troy Poulter May 28 '17 at 23:05
0

Use modulo operation as shown below

if (value % 5 == 0)

Read more about modulo operation here

Jobin
  • 5,610
  • 5
  • 38
  • 53
Ximbot
  • 19
  • 3