1. 程式人生 > >java中的三目運算

java中的三目運算

ava 基礎 system ring args 復習 value println 代碼

直接上代碼!復習基礎!

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

java中的三目運算