public class FirstDemo {
/**
* 数组从大到小排序
*/
* 数组从大到小排序
*/
public static void main(String[] args) {
int a[] = {3,5,7,2,4,7,2,1};
paixu(a);
dayin(a);
}
int a[] = {3,5,7,2,4,7,2,1};
paixu(a);
dayin(a);
}
private static void dayin(int temp[]) {
//打印从大到小的数组数据
for (int i = 1; i < temp.length; i++) {
System.out.print(temp[i]+"\t");
}
}
//打印从大到小的数组数据
for (int i = 1; i < temp.length; i++) {
System.out.print(temp[i]+"\t");
}
}
private static void paixu(int temp[]) {
//System.out.print("\n数组从小到大排序");
for (int i = 1; i < temp.length; i++) {
for (int j = 0; j < temp.length; j++) {
if (temp[i]<temp[j]) {
int x = temp[i];
temp[i]=temp[j];
temp[j] = x;
}
}
}
}
//System.out.print("\n数组从小到大排序");
for (int i = 1; i < temp.length; i++) {
for (int j = 0; j < temp.length; j++) {
if (temp[i]<temp[j]) {
int x = temp[i];
temp[i]=temp[j];
temp[j] = x;
}
}
}
}
}
转载于:https://blog.51cto.com/haiyuanxi/912530