赋值运算符 += 面试题小陷阱
来源:互联网 发布:淘宝联盟认证怎么弄 编辑:程序博客网 时间:2024/06/01 22:16
package day;
public class Test_01 {
public static void main(String[] args) {
int i =12;
/* i+=i; i=i+i —— 24
i*=2+3; i=i*(2+3) ——60
i-=2; i=i-2 —— 10
_____
240 |120
10
-----
20
20
------
0
int j =3;
j+=4;// j=j+4 ;3+4=7 j是7
System.out.println(j);
short c = 2;
//c =c +3 ;编译报错,因为这是两次运算,第一次相加,第二次赋值,不会自动转换类型
c+=3;// 计算方式c=c+3 ;= 2+3 =5 这是一次运算,只做了一次赋值运算,会自动转换
System.out.println(c);
//面试题 ,请指出下面2条题目哪个能正常编译?
short s =1; //(同上)
//s =s+1;
short s2 =1;
s2+=1;
}
}
public class Test_01 {
public static void main(String[] args) {
int i =12;
/* i+=i; i=i+i —— 24
i*=2+3; i=i*(2+3) ——60
i-=2; i=i-2 —— 10
i/=i+i; i=i/(i+i)—— 0//因为i是int类型所以只保留整数部分
_____
240 |120
10
-----
20
20
------
0
*/
int j =3;
j+=4;// j=j+4 ;3+4=7 j是7
System.out.println(j);
short c = 2;
//c =c +3 ;编译报错,因为这是两次运算,第一次相加,第二次赋值,不会自动转换类型
c+=3;// 计算方式c=c+3 ;= 2+3 =5 这是一次运算,只做了一次赋值运算,会自动转换
System.out.println(c);
//面试题 ,请指出下面2条题目哪个能正常编译?
short s =1; //(同上)
//s =s+1;
short s2 =1;
s2+=1;
}
}
阅读全文
0 0
- 赋值运算符 += 面试题小陷阱
- 赋值运算符面试题
- 面试题1 赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题(一) 赋值运算符
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 面试题1:赋值运算符函数
- 【面试题1】赋值运算符函数
- 面试题1:赋值运算符函数
- 剑指Offer:面试题01---赋值运算符函数
- 面试题1:赋值运算符函数深度剖析
- 剑指offer 面试题1:赋值运算符
- 剑指offer面试题(一):赋值运算符函数
- MD5+Salt加密
- 流程图解Spring Framework(七) Spring 如何创建代理的--jdk?
- 学习就是机会
- 《算法竞赛入门经典(第二版)》学习之路!
- 流程图解Spring Framework(八) Spring 如何创建代理的--cglib?
- 赋值运算符 += 面试题小陷阱
- 基(là)础(jī)线段树详解
- golang Leaf 游戏服务器框架简介
- centos7的防火墙(firewalld)
- 流程图解Spring Framework(九) Spring 如何进行事务管理的?
- MySQL存储过程与触发器(应用场景)
- PriorityBlockingQueue
- offee
- Eclipse安装插件地址集合