1.请问ret的值是多少?
<span style="color:#ff0000;">package Test;
public class test {
public static void main(String args[]) {
int k = 0;
int res = ++k + k++ + ++k + k;
System.out.println(res);
}
}
</span>
2.问下列每条语句运行结束后i,j,k的值?
<span style="color:#ff0000;">package Test;
public class test {
public static void main(String args[]) {
int i = 0;
int j = i++ + ++i;
int k = --i + i--;
}
}
</span>
<div><div><span style="color:#ff6600;">*</span>3.以下代码运行后的结果?<span style="color:#ff0000;">
</span></div></div><div><pre name="code" class="java"><span style="color:#ff0000;">package Test;
public class test {
public static void main(String args[]) {
int j = 0;
for (int i = 0; i < 100; i++) {
j = j++;
}
System.out.println(j);
}
}
</span>
4.
存在使
i + 1 < i
的数吗
?
答案:
1.答案是:8
<span style="color:#ff0000;">int res = ++k + k++ + ++k + k;//1+1+3+3</span>
<span style="color:#333333;">2.答案:(1)i=2,j=2. (2)k=2,i=0</span>
<span style="color:#ff0000;">int j = i++ + ++i; //j=0+2 i=2</span>
<span style="color:#ff0000;">int k = --i + i--; //k=1+1 i=0</span>
<span style="color:#cc0000;">*</span><span style="color:#333333;">3.答案:0</span>
<pre name="code" class="java" style="color: rgb(51, 51, 51);"><span style="color:#ff0000;">for (int i = 0; i < 100; i++) {
j = j++;
} //在每次循环过后的赋值j都是0,没有实现加一的目的</span>
4.答案:
<span style="color:#ff0000;">存在,当变量超出范围的时候就存在i+1<i. 例如:当 i=2147483647+1;i=-2147483648;</span>
<span style="color:#ff0000;">
</span>
<span style="color:#ff0000;">
</span>
<span style="color:#ff0000;"><span style="color: rgb(204, 0, 0); font-family: Arial; font-size: 14px; line-height: 26px;"> </span></span>
<span style="color:#ff0000;"><span style="color: rgb(204, 0, 0); font-family: Arial; font-size: 14px; line-height: 26px;"> 希望大神能够指点一些错误和补充一些知识,谢谢</span>
</span>