该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2010-06-02
nickevin 写道 int j = 10; for (int i = 0; i < 100; i++) { j = j + j; } System.out.println(j); 改造一下 结果如何 这个怎么也是0,解释哈 |
|
返回顶楼 | |
发表时间:2010-06-02
最后修改:2010-06-02
taote 写道 nickevin 写道 int j = 10; for (int i = 0; i < 100; i++) { j = j + j; } System.out.println(j); 改造一下 结果如何 这个怎么也是0,解释哈 已经解释了: 追踪i和j的变化值如下: j i 838860800 22 1677721600 23 -939524096 24 -1879048192 25 536870912 26 1073741824 27 -2147483648 28 0 29 也就是说当i=28时,j为最小的int值,两个最小的int值相加就是0(可以换成二进制进行运算可得) 我的理解,请指正 |
|
返回顶楼 | |
发表时间:2010-06-02
java疑惑中问题吧,怎么大多数都是!!
|
|
返回顶楼 | |
发表时间:2010-06-02
真是 防人之心不可无呀
|
|
返回顶楼 | |
发表时间:2010-06-02
public static void main(String[] args) {
String classPath = "java.lang.String"; System.out.println(classPath.replaceAll(".", "/")); } 谁能指教一下这个答案为什么是:“///////////////” |
|
返回顶楼 | |
发表时间:2010-06-02
chilongxph 写道 public static void main(String[] args) {
String classPath = "java.lang.String"; System.out.println(classPath.replaceAll(".", "/")); } 谁能指教一下这个答案为什么是:“///////////////” replaceAll(regex,replaceStr);他的第一个参数表示正则字符串。在正则表达式中"."的含义如下 . 除行终止符外的任何字符(如果DOTALL标志置位,则表示任何字符) 结果因替换了所有。。。。 |
|
返回顶楼 | |
发表时间:2010-06-02
IrenBJ 写道
towne 写道
wnick 写道
IrenBJ 写道
5。 public class Increment { public static void main(String[] args) { int j = 0; for (int i = 0; i < 100; i++) j = j++; System.out.println(j); } }
求打印结果?
请在机器上跑下面这句话 int j = 0 ; System.out.println(j++); 和 int j = 0 ; System.out.println(++j); 两个比较一下
j++,++j,前者是先赋值,后者是先运算这是没有错。 int j=0; j=j++; 这里是先把值赋值给j即是j=0;那么++运算怎么没有执行? 你上面的解析根本不对,如果你用一个x变量来存储不用j那么x就会是100. |
|
返回顶楼 | |
发表时间:2010-06-02
jspine 写道 chilongxph 写道 public static void main(String[] args) {
String classPath = "java.lang.String"; System.out.println(classPath.replaceAll(".", "/")); } 谁能指教一下这个答案为什么是:“///////////////” replaceAll(regex,replaceStr);他的第一个参数表示正则字符串。在正则表达式中"."的含义如下 . 除行终止符外的任何字符(如果DOTALL标志置位,则表示任何字符) 结果因替换了所有。。。。 因为这里是regex替换,在regex中"."代表任意字符。 |
|
返回顶楼 | |
发表时间:2010-06-02
chilongxph 写道 public static void main(String[] args) {
String classPath = "java.lang.String"; System.out.println(classPath.replaceAll(".", "/")); } 谁能指教一下这个答案为什么是:“///////////////” 可以翻一下正则表达式。如果想达到预想的结果:java/lang/String,必须先转义: System.out.println(classPath.replaceAll("\\.", "/")); |
|
返回顶楼 | |
发表时间:2010-06-02
第七题也太坏了点,谁知道2000年的1月31号是星期几啊。。。。
|
|
返回顶楼 | |