import java.util.Scanner;
public class MaxMin {
public MaxMin(int x, int y, int z){
int t;
int ThreeNum[] = {x, y, z};
for(int i = 0; i < ThreeNum.length - 1; i++)
{
for(int j = 0; j < ThreeNum.length - 1 - i; j++)
{
if(ThreeNum[j] > ThreeNum[j + 1])
{
t = ThreeNum[j];
ThreeNum[j] = ThreeNum[j+1];
ThreeNum[j+1] = t;
}
}
}
System.out.println("The oder of this three numbers:");
for(int i = 0; i < ThreeNum.length; i++)
System.out.print(ThreeNum[i] + " ");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int x, y, z;
Scanner scan = new Scanner(System.in);
System.out.println("Input three number:");
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
new MaxMin(x, y, z);
}
}
首先将输入进来的3个数存入数组里,然后通过冒泡排序来进行排序,最后再输出3个数的顺序。
结果: