02.运算符与表达式
时间:2016-08-28 17:47:59
收藏:0
阅读:190
- Java当中的运算符
- 要点一:
- int i = 3 / 2,请问 i 的值?
publicclassTest{publicstaticvoid main(String args[]){int i =3/2;System.out.println(i);}}
- 要点二:
- i++与++i的区别?
publicclassTest{publicstaticvoid main(String args[]){int i =5;int j = i+++5;System.out.println(i);System.out.println(j);}}
- i++是先运算,后自加;++i是先自加,再运算。
- 要点三: = 与 == 的区别?
- = :是赋值号,== 是判断左右两边是否相等并返回boolean值。
publicclassTest{publicstaticvoid main(String args[]){int i =5;int j =6;boolean b = i == j;System.out.println(b);}}
- 逻辑运算符

- 短路与 a && b,会先判断a的真假,若为假,后面的b不运算。而逻辑与 a & b,都会运算。
- publicclassTest{
- publicstaticvoid main(String args[]){
- boolean a =true;
- boolean b =false;
- boolean c = a & b;
- boolean d = a && b;
- System.out.println(c);
- System.out.println(d);
- int i =5;
- boolean e = i >6&& i++>7;
- System.out.println(e);
- System.out.println(i);
- }
- }
原文:http://www.cnblogs.com/arroneve/p/5815362.html
评论(0)
