# 三位数排序，数组排序

``````public class Count {
/** * 给出三位数，进行三位数排序 * * @param args */

public static void main(String[] args) {
// TODO Auto-generated method stub

int a = 100;
int b = 93;
int c = 56;
if(a>=b) {
int temp=a;
a=b;
b=temp;
}
if(a>=c) {
int temp=a;
a=c;
c=temp;
}
if(b>=c) {
int temp=b;
b=c;
c=temp;
}

System.out.println(a + "\n" + b + "\n" + c);
}
}
``````

``````public class Count1 {

public static void main(String[] args) {
// TODO Auto-generated method stub

// 给出一个四位数，进行排序
/** * 注意：复制过程中，要改参数，不该参数，就会出问题，我就是没改参数费了好大的力气，以为方法有问题 * */
int a = 5;
int b = 6;
int c = 2;
int d = 4;
if (a >= b) {
int temp = a;
a = b;
b = temp;
}
if (a >= c) {
int temp = a;
a = c;
c = temp;
}
if (a >= d) {
int temp = a;
a = d;
d = temp;
}
if (b >= c) {
int temp = b;
b = c;
c = temp;
}
if (b >= d) {
int temp = b;
b = d;
d = temp;
}
if (c >= d) {
int temp = c;
c = d;
d = temp;
}
System.out.println(a + "\n" + b + "\n" + c + "\n" + d);
}

}``````

public class Array {

``````/**
* 给出一个数组，进行数组里面的值进行排序
*
* @param args
*/

public static void main(String[] args) {

int array[] = { 26, 12, 67, 45, 89, 32 };

for (int i = 0; i <array.length; i++) {
for (int j = 0; j <array.length - i - 1; j++) {
if (array[j] >= array[j + 1]) {
int temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;

}
}

}

for (int x : array) {
System.out.println(x);
}
}
``````

}

``````if (array[j] >= array[j + 1]) {
int temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;``````

原文作者：听琴一曲
原文地址: https://blog.csdn.net/qq_42960881/article/details/82386001
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。