随笔分类 -  java谜题

摘要:8,三元运算符 public class DosEquis{ public static void main(String[] args){ char x = 'X'; int i = 0; System.out.println(true ? x : 0); System.out.println(false ? i : x); } } 打印... 阅读全文
posted @ 2013-01-14 23:30 sqtds 阅读(109) 评论(0) 推荐(0)
摘要:谜题1,奇数性 public static boolean isOdd(int i ){ return i%2==1;}当 i 是一个负奇数时,i % 2 等于-1 而不是1, 因此 isOdd 方法将错误地返回 false。为了防止这种意外,请测试你的方法在为每一个数值型参数传递负数、零和正数数值时,其行为是否正确。 这个问题很容易订正。只需将 i % 2 与 0 而不是与1 比较,并... 阅读全文
posted @ 2013-01-10 23:49 sqtds 阅读(290) 评论(0) 推荐(0)