import java.util.Scanner;
class scanner_import {
public static void main (String[] agrs ){
Scanner sc = new Scanner (System.in);
System.out.println("请输入第一个整数");
int x = sc.nextInt();
System.out.println("请输入第二个整数");
int y = sc.nextInt();
System.out.println("请输入第三个整数");
int z = sc.nextInt();
三元运算符
int max = (x > y) ? ((x > z) ? x : z) : ((y > z)? y : z);
int min = (x < y) ? ((x < z) ? x : z) : ((y < z)? y : z);
int mid = (x > y) ? ((x < z) ? x : ((y > z) ? y : z))): ((x > z) ? x : ((y > z) ? z :y))
}
}
if和任意转换三个数的值
if (a>b){
temp = a;
a = b;
b = temp;
}
if (a>c){
temp = a;
a = c ;
c = temp;
}
if (b>c){
temp = b;
if (a>b){
temp = a;
a = b;
b = temp;
}
if (a>c){
temp = a;
a = c ;
c = temp;
}
if (b>c){
temp = b;
三元运算符
int x = (a<b)?a:b;
int y = (a>=b)?a:b; // y为ab中的大值
int m = (x<c)?x:c; //m 为最小值
int n = (x>=c)?x:c; //n 为xc中的大值
int p = (y<n)?y:n; // p为第二小值
int q = (y>=n)?y:n; //q为最大值 |
|