小猪学Java篇十六(Java基础语法------------运算符---三元运算符(条件运算符))

package operator;
// 【运算符】---------------------三元运算符(条件运算符?:) 【必须掌握】
public class Demo08 {
public static void main(String[] args) {
// x ? y : z
//如果x==true, 则结果为y, 否则结果为z 如果把x写成a+b ,如果为真就走y这个结果,为假就走z这结果
//例子如下:

int socre = 80;
String type = socre <60 ?"不及格":"及格"; //输出及格,条件为假 【必须掌握】
System.out.println(type);

// int socre = 50;
// String type = socre <60 ?"不及格":"及格"; 输出不及格,条件为真 【必须掌握】
// System.out.println(type);

//if 以后学if 流程控制



// 拓展测试:::::!!!!!!!!! 【优先级】: 一元运算符、加减乘除、位于、相等按位与

}
}
posted @ 2022-10-01 11:29  小猪很努力  阅读(12)  评论(0)    收藏  举报