java 心得

11. 最后的笑声

1 package javaBookPractice;
2 
3 public class LastLaugh {
4     public static void main(String[] args) {
5         System.out.println("H"+"a");      //
6         System.out.println('H'+'a');      //会自动提升为整型 A=65,a=97 最后等于169
7     }
8 }

 1. 奇数性

 1 package javaBookPractice;
 2 
 3 public class TestIsOdd {
 4     public static void main(String[] args) {
 5         System.out.println(TestIsOdd.isOdd(3));
 6         System.out.println(TestIsOdd.isOdd(-1));   //返回-1,下面判断的是 1,没考虑到负数情况
 7         System.out.println();
 8         System.out.println(TestIsOdd.isOdd2(3));
 9         System.out.println(TestIsOdd.isOdd2(-1));  //用 0 来就是可以的
10 } 11 public static boolean isOdd(int i){ //wrong 12 return i%2 == 1; 13 } 14 public static boolean isOdd2(int i){   //right 15 return i%2 != 0; 16 } 17 }

 9. 半斤

  请给出对变量 x 和 i 的声明,使得满足下列条件:

    x += i;     //合法

    x = x + i;    //不合法

    waiting...

    waiting...


160927

10. 下面这段代码循环不会执行

1        for(int i =0; i<0; i++){
2             System.out.println("exec "+i);
3         }     

160927


 

posted @ 2016-09-23 20:22  乙侍  阅读(200)  评论(0编辑  收藏  举报