java基础学习——变量,java基本类型,运算符和表达式笔试题

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>

 

 


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值