博客
关于我
JAVA条件运算符
阅读量:347 次
发布时间:2019-03-04

本文共 521 字,大约阅读时间需要 1 分钟。

  笔者随意些的一篇小文章访问居然挺高,但是看起来有点简陋,在补充一些小图方便理解,可能是不知道条件运算符是什么有点忘了,看到三目,三元就知道了.

条件运算符(?:)

条件运算符也被称为三元运算符。该运算符有3个操作数,并且需要判断布尔表达式的值。该运算符的主要是决定哪个值应该赋值给变量。

variable x = (expression) ? value if true : value if false

代码:

public class Test {//公共测试类,与文件名相同	public static void main(String[] args){//main程序入口        int score = 80;         int x = -100;        String type =score<60?"不及格":"及格";         int flag = x > 0 ? 1 : (x == 0 ? 0 : -1);        System.out.println("type= " + type);        System.out.println("flag= "+ flag);}}

运行效果:

转载地址:http://szzr.baihongyu.com/

你可能感兴趣的文章
nginx http配置说明,逐渐完善。
查看>>
Nginx keepalived一主一从高可用,手把手带你一步一步配置!
查看>>
Nginx Location配置总结
查看>>
Nginx log文件写入失败?log文件权限设置问题
查看>>
Nginx Lua install
查看>>
nginx net::ERR_ABORTED 403 (Forbidden)
查看>>
vue中处理过内存泄露处理方法
查看>>
Nginx RTMP 模块使用指南
查看>>
Nginx SSL 性能调优
查看>>
nginx ssl域名配置
查看>>
Nginx SSL私有证书自签,且反代80端口
查看>>
Nginx upstream性能优化
查看>>
Nginx 中解决跨域问题
查看>>
nginx 代理解决跨域
查看>>