码迷,mamicode.com
首页 > 编程语言 > 详细

java 解惑

时间:2016-09-23 21:24:49      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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...

 

java 解惑

标签:

原文地址:http://www.cnblogs.com/daydayhave/p/5901533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!