利用条件运算符的嵌套来完成学生成绩的表示

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

程序分析:(a>b)?a:b这是条件运算符的基本例子。

 1 package com.li.FiftyAlgorthm;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * 题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分 之间的用B表示,60分以下的用C表示。
 7  * 程序分析:(a>b)?a:b这是条件运算符的基本例子。
 8  * 
 9  * @author yejin
10  */
11 public class Condition {
12     // public static final int S1 = 90;
13     // public static final int S2 = 60;
14     static int grade;
15 
16     public static void main(String[] args) {
17         Scanner str = new Scanner(System.in);
18         int s = str.nextInt();
19         Condition c = new Condition();
20         grade = c.compare(s);
21         if (grade == 1) {
22             System.out.print('A');
23         } else if (grade == 2) {
24             System.out.print('B');
25         } else {
26             System.out.println('C');
27         }
28     }
29 
30     public int compare(int s) {
31         return s > 90 ? 1 : s > 60 ? 2 : 3;
32     }
33 }
原文地址:https://www.cnblogs.com/justdoitba/p/7142377.html