java中的三目運算


直接上代碼!復習基礎!

public static void main(String args[]){
int a , b;
a = 10;

b = (a == 1) ? 20: 30;//如果a等於1那么b就等於20,否則等於30

System.out.println( "Value of b is : " + b );
b = (a == 10) ? 20: 30;
System.out.println( "Value of b is : " + b );

}
}

打印:

Value of b is : 30
Value of b is : 20


免責聲明!

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



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