三元运算符

 1  2 
 3 public class Demo08 {
 4     public static void main(String[] args) {
 5         //x ? y : z
 6         //如果x==true,则结果为y,否则结果为z
 7 
 8         int score = 50;
 9         String type = score < 60 ? "不及格":"及格";
10         System.out.println(type);
11     }
12 }

 

posted @ 2021-02-22 17:13  浅小墨  阅读(28)  评论(0)    收藏  举报