使用三元運算子查詢三個數字中最大數字的 Java 程式
條件運算子也稱為三元運算子。該運算子包含三個運算元,用於求值布林表示式。該運算子的目標是確定應將哪個值分配給變數。運算子寫為 -
variable x = (expression) ? value if true : value if false
示例
public class LargestOf3Nums_TernaryOperator {
public static void main(String args[]) {
int a, b, c, temp, result;
a = 10;
b = 20;
c = 30;
temp = a < b ? a:b;
result = c < temp ? c:temp;
System.out.println("Largest number is ::"+result);
}
}輸出
Largest number is ::30
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP