public static boolean isOdd(int i){ return i % 2 == 1; }
上面的方法真的能找到所有的奇数么?
数据分析师2017-10-01 00:29:53
Can all odd numbers be found by writing this way? -PHP Chinese website Q&A-Can all odd numbers be found by writing this way? -PHP Chinese website Q&A
Let’s take a look and learn.
伊谢尔伦2017-02-24 13:13:04
这里没有考虑到负数问题,如果i为负则不正确。应该改成return i%2 == 0
完整代码:
public static boolean isOdd(int i){ return i % 2 == 0; }