i++ 和 ++i;&& 和 &


一、算數運算符(自增運算符i++、自減運算符i++)

 ※  i++是先賦值(計算)再加1 ;++i是先加1再賦值(計算) ;

 

int m = 5;
boolean bool = ++m > 5;
System.out.println(m);
System.out.println(bool+"\n");
		
int x = 8;
boolean bool1 = x++ > 8;
System.out.println(bool1);
System.out.println(x+"\n");

 

運行結果:

二、邏輯運算符(&&)

1.稱為邏輯與運算符。當且僅當兩個操作數都為真,條件才為真。

2.&&是短路與:計算左邊表達式若正確在計算右邊表達式;如果左邊表達式false右邊表達式不計算;

int y = 4;
System.out.println(true && y++ > 3);
System.out.println(y);

int z = 4;
System.out.println(false && z++ > 3);
System.out.println(z);        

運行結果:

三、位移運算符

 &  :如果相對應位都是1,則結果為1,否則為0;

※奇數和1 按位與 得 1  偶數和1 按位與 得 0

int a = 3;
int b = 1;
int c = 8;
System.out.println(a&b);
System.out.println(a&c);

 運行結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM