码迷,mamicode.com
首页 > 其他好文 > 详细

02.运算符与表达式

时间:2016-08-28 17:48:12      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

  • Java当中的运算符
技术分享
 
  • 要点一:
    • int i = 3 / 2,请问 i 的值?
  1. publicclassTest{
  2. publicstaticvoid main(String args[]){
  3. int i =3/2;
  4. System.out.println(i);
  5. }
  6. }
 
  • 要点二:
    • i++与++i的区别?
  1. publicclassTest{
  2. publicstaticvoid main(String args[]){
  3. int i =5;
  4. int j = i+++5;
  5. System.out.println(i);
  6. System.out.println(j);
  7. }
  8. }
      • i++是先运算,后自加;++i是先自加,再运算。
 
  • 要点三: = 与 == 的区别?
    • = :是赋值号,== 是判断左右两边是否相等并返回boolean值。
  1. publicclassTest{
  2. publicstaticvoid main(String args[]){
  3. int i =5;
  4. int j =6;
  5. boolean b = i == j;
  6. System.out.println(b);
  7. }
  8. }
 
  • 逻辑运算符技术分享
 
    • 短路与 a && b,会先判断a的真假,若为假,后面的b不运算。而逻辑与 a & b,都会运算。
  1. publicclassTest{
  2. publicstaticvoid main(String args[]){
  3. boolean a =true;
  4. boolean b =false;
  5. boolean c = a & b;
  6. boolean d = a && b;
  7. System.out.println(c);
  8. System.out.println(d);
  9. int i =5;
  10. boolean e = i >6&& i++>7;
  11. System.out.println(e);
  12. System.out.println(i);
  13. }
  14. }
 





02.运算符与表达式

标签:

原文地址:http://www.cnblogs.com/arroneve/p/5815362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!