检测int是否每100更改一次 [英] Detect if int changes per 100

查看:65
本文介绍了检测int是否每100更改一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标题中总结了我的问题。如果我有一个int,它达到100里程碑,然后是200及之后。如何在不需要编写多个if语句的情况下检测到这一点?

Pretty much summed up my question in the title. If I have a int and it reaches the 100 milestone followed by 200 and onwards. How would I detect this without needing to write multiple if statements?

推荐答案

使用模运算符来检测数字除以100时是否保留余数,因此是100的倍数:

Use the modulo operator to detect when the number, divided by 100, leaves no remainder and is therefore a multiple of 100:

for (int i = 0; i < 1000000; i++) {
    if ((i % 100) == 0) {
        // Do thing every 100
    }
}

这篇关于检测int是否每100更改一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆