if 使用过程中可能遇到的坑顶折在第6行,if后面有一个分号; 而分号也是一个完整的表达式如果b为true,会执行这个分号,然后打印yes如果b为false,不会执行这个分号,然后打印yes这样,看上去无论如何都会打印yespublic class HelloWorld { public static void main(String[] args) { boolean b = false; if (b); System.out.println(“yes”); }}if else顶折else 代表不成立的情况public class HelloWorld { public static void main(String[] args) { boolean b = false; if (b) System.out.println(“yes”); else System.out.println(“no”); }}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...