package com.briup.job;
import java.util.Scanner;
public class Sort{
public static void main(String[] agrs){
Scanner sc = new Scanner(System.in);
System.out.println("请输入要排序的三个数:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int t = 0;
if (a>b) { //保证a<b
t = a;
a = b;
b = t;
}
if (b>c) { //保证b<c
t = b;
b = c;
c = t;
}
if (a>c) { //保证a<c
t = a;
a = c;
c = a;
}
System.out.println(a+"<"+b+"<"+c);
}
}
输入三个int型的数据,放入到a,b,c三个变量中去,使用条件结构与交换逻辑将这三个变量中的值从小到大排列。
最新推荐文章于 2023-08-07 23:58:31 发布