【Java算法】条件运算符

利用条件运算符的嵌套来完成此题:学习成绩> =90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。

条件运算符的表达式为:

表达式1?表达式2:表达式3

当表达式1为true时,取表达式2;当表达式为false时,取表达式3.

1 public class TiaojianYunsuanfu {
2     public static void main(String[] args) {
3         int score = 21;
4         char Level = score>=90?'A':(score<60?'C':'B');
5         System.out.println("the level is "+Level);
6     }
7 }
原文地址:https://www.cnblogs.com/Jourly/p/5474428.html