package OldOrSmall;
import java.util.Scanner;
public class EstimatedOldOrSmall {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan =new Scanner(System.in);//定义输入数组方法
int[] aArray = new int[10];//定义int型长度为10的数组
System.out.println("请输入字符串aArray:");
for(int i=0; i<aArray.length; i++) {
aArray[i] = scan.nextInt();//输入数组方法
System.out.print(aArray[i] + " ");
}
System.out.println();
swap(aArray);//调用swap函数
for(int i=0; i<aArray.length; i++) {
System.out.print(aArray[i] + " ");
}
}
//利用冒泡法将一组数从大到小排序
private static void swap(int[] bArray) {
// TODO Auto-generated method stub
for(int i=0; i<bArray.length-1; i++) {
for(int j=0; j<bArray.length-1-i; j++) {
if(bArray[j]<bArray[j+1]) {
int temp = bArray[j];
bArray[j] = bArray[j+1];
bArray[j+1] = temp;
}
}
}
}
}
运行结果:
请输入字符串aArray:
1 2 4 6 8 9 3 5 7 10
1 2 4 6 8 9 3 5 7 10
10 9 8 7 6 5 4 3 2 1