Java基础编程1—比较三个整数的大小

来源:互联网 发布:anconda tensorflow 编辑:程序博客网 时间:2024/05/21 15:49
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);}}

原创粉丝点击