java中mod的语法是什么 [英] What's the syntax for mod in java
本文介绍了java中mod的语法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以伪代码为例:
if ((a mod 2) == 0)
{
isEven = true;
}
else
{
isEven = false;
}
推荐答案
对于非负整数,可以使用 remainder 运算符,而不是语义略有不同的模运算符 %
.对于您的确切示例:
Instead of the modulo operator, which has slightly different semantics, for non-negative integers, you can use the remainder operator %
. For your exact example:
if ((a % 2) == 0)
{
isEven = true;
}
else
{
isEven = false;
}
这可以简化为单行:
isEven = (a % 2) == 0;
这篇关于java中mod的语法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文