import java.util.Scanner;
/**
* 输入三个整数x,y,z,请把这三个数由小到大输出。
*
* @author xingyang
*
*/
public class test15 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x, y, z, min, max, mid;
System.out.print("输入第一个数字:");
x = sc.nextInt();
System.out.print("输入第二个数字:");
y = sc.nextInt();
System.out.print("输入第三个数字:");
z = sc.nextInt();
min = x < y ? (x < z ? x : z) : (y < z ? y : z);
max = x > y ? (x > z ? x : z) : (y > z ? y : z);
mid = x > min && x < max ? x : (y > min && y < max ? y : z);
System.out.println("三个数字由小到大排列为: " + min + "<" + mid + "<" + max);
}
}
Java基础编程1—比较三个整数的大小
最新推荐文章于 2023-01-26 11:58:35 发布