当值达到5的倍数时如何调用方法

How to call a method when a value reaches multiples of 5

我有 Firebase 数据库,其中为特定用户存储了一个数字值。我想在值达到 5 的倍数时显示广告,从 0 开始。

我可以使用这样的 if 语句让它调用第一个 5 的倍数的方法

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

我如何编辑它以便它在 10、15、20、25 等位置调用它?

尝试取模运算。

if (dls % 5 == 0) {
    Toast.makeText(c,"Testing it worked here",Toast.LENGTH_LONG).show();

使用模运算如下图

if (value % 5 == 0)

阅读有关模运算的更多信息here