其他分享
首页 > 其他分享> > 条件运算符

条件运算符

作者:互联网

x? y:z //x值如果为true=y,如果为false=z;

如:

public class day0928 {
    public static void main(String[]args){
        int  score= 60;
        int  fh=80;
        int  yb=67;
        int   pm=50;
        System.out.println("fh:"+(fh>=score?"及格":"不及格"));
        System.out.println("fh:"+(yb>=score?"及格":"不及格"));
        System.out.println("fh:"+(pm>=score?"及格":"不及格"));
    }
}

运行结果:

fh:及格

fh:及格

fh:不及格

 

也可以使用”if"来进行判断。

标签:及格,int,System,运算符,不及格,score,条件,fh
来源: https://www.cnblogs.com/yhcTACK/p/15354884.html