5
A
回答
24
%
确实在Java中求余运算。
要得到适当的弹性模量,可以使用剩余的功能:
它使用三元操作做标志修正最短:
private int mod(int x, int y)
{
int result = x % y;
return result < 0? result + y : result;
}
对于那些谁不喜欢三元运算符,这是等效的:
private int mod(int x, int y)
{
int result = x % y;
if (result < 0)
result += y;
return result;
}
8
因为如果您将-2除以6,则会得到-2作为余数。 %运算符将会像下面一样给出余数;
int remainder = 7 % 3; // will give 1
int remainder2 = 6 % 2; // will give 0
要得到模:
// gives m (mod n)
public int modulo(int m, int n){
int mod = m % n ;
return (mod < 0) ? mod + n : mod;
}
+0
好的,但是我怎样才能在Android中获得mod? – 2012-02-08 22:42:07
相关问题
- 1. 超载运营商<<
- 2. 运营商<<超载
- 3. 运营商<<重载
- 4. 虚拟<<运营商
- 5. 运营商<<在C#
- 6. Ruby:<< - 运营商
- 7. 全球运营商<<和成员运营商之间的共存<<
- 8. 模板运营商<<变圆了
- 9. 运营商<<(ostream&os,...)模板类
- 10. 错误不符合运营商<<
- 11. 即使我超载`运营商<<`
- 12. 我想超载运营商<<
- 13. 整数推广与运营商<<
- 14. 超负荷运营商<<类模板
- 15. 运营商<<重载在C++中
- 16. 运营商<< and >>重载
- 17. ostream的deferencing运营商<<
- 18. <<运营商红宝石
- 19. 运营商<<重载 - C++和Java
- 20. stringstream的运营商<<崩溃(malloc_consolidate)
- 21. 运营商的解释<< overload
- 22. 可以专门运营商<<?
- 23. 运营商<<在派生类C++
- 24. 主叫运营商<< in gdb
- 25. 的Javascript运营商<< and >>
- 26. 禁止运营商<<致电
- 27. ActiveRecord的铲运营商<<
- 28. 暧昧运营商<<选择
- 29. <a href=""></a>不工作
- 30. 错误:对不明确的超负荷“运营商<<”
谢谢唐,它的工作原理。 – 2012-02-08 22:47:15
@don roby:这个操作符意味着什么:返回结果<0?结果+ y:结果;谢谢 – Kenji 2014-02-26 12:22:21
@Kenji - 请参阅[wikipedia on ternary operator?:](http://en.wikipedia.org/wiki/%3F :) – 2014-02-26 12:47:35