//<editor-fold defaultstate="collapse" desc="if 簡潔版(ConditionalOperator三元運算子)">
package conditional.operator;
public class ConditionalOperator
{
public static void main(String[] args)
{
String str=1>3? "1大於3" : "1小於3";
System.out.println(str); //用字串判斷
char c=91>10?'Y':'N';
System.out.println(c); //用字元判斷
int num=20>108? 1:0;
System.out.println(num); //用數值判斷
long leng=16>8? 88:99;
System.out.println(leng); //用長整數判斷
boolean bo=9>6? true:false;
System.out.println(bo); //用布林值判斷
}
}
//</editor-fold>
/*結果*/
1小於3
Y
0
88
true
全站熱搜
留言列表