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

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

条件运算符(?:)

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

条件运算符的语法格式为:variable x = (expression) ? value if true : value if false。

public class Test { public static void main(String[] args) { 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/

你可能感兴趣的文章
python 微信扫码登录_python实现微信第三方网站扫码登录(Django)
查看>>
Python 快速下载依赖
查看>>
python实现非参数统计的Cochran检验 (附完整源码)
查看>>
python 怎么验证是否安装成功 scrapy
查看>>
Python 手写数字识别-1
查看>>
Python实现接口自动化测试库(JSON与Requests)详解
查看>>
Python 手写数字识别-3-sklearn中的几种算法
查看>>
python实现SSIM和MSSSIM计算 (附完整源码)
查看>>
Python 打开文件注意事项
查看>>
python 批量修改文件名_python windows下批量修改文件名
查看>>
Python 抓取网页乱码问题 以及EXCEL乱码
查看>>
python 抓取网页内容
查看>>
python 按照当前日期创建文件
查看>>
Python 接口并发测试详解
查看>>
Python 接口自动化 —— requests框架
查看>>
python 接口自动化数据结构(如列表、字典、元组)
查看>>
Python 接口自动化测试中的深拷贝与浅拷贝~
查看>>
Python 接口自动化测试中的高阶函数
查看>>
python 控制 cmd 命令行颜色
查看>>
Python 操作 Azure Blob Storage
查看>>