Exer03.java 583 B

1234567891011121314151617181920212223242526272829
  1. class Exer03
  2. {
  3. public static void main(String[] args)
  4. {
  5. //1)对下列代码,若有输出,指出输出结果。
  6. int x = 4;
  7. int y = 1;
  8. if (x > 2) {
  9. if (y > 2) // 省略{} 只有一条语句
  10. System.out.println(x + y);
  11. // 不是语句体
  12. System.out.println("lovecoding");
  13. } else
  14. System.out.println("x is " + x);
  15. boolean b = true;
  16. //如果写成if(b=false)能编译通过吗?如果能,结果是?
  17. if(!b) //建议:if(!b)
  18. System.out.println("a");
  19. else if(b)
  20. System.out.println("b");
  21. else if(!b)
  22. System.out.println("c");
  23. else
  24. System.out.println("d");
  25. }
  26. }