/*
输入5个数据,进行升序排序
*/
import java.util.Scanner;
class Demo3{
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int [] bb=new int [5];
System.out.println("请输入第一个数");
bb[0] = s.nextInt();
System.out.println("请输入第二个数");
bb[1] = s.nextInt();
System.out.println("请输入第三个数");
bb[2] = s.nextInt();
System.out.println("请输入第四个数");
bb[3] = s.nextInt();
System.out.println("请输入第五个数");
bb[4] = s.nextInt();
paixu b = new paixu ();
b.arrange(bb);
}
}
class paixu {
public void arrange( int arr []) {
for (int i=0;i<=arr.length-1 ;i++ ) {
for (int j=0;j<=arr.length-2-i ;j++ ) {
if (arr[j]>arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for (int x=0;x<=arr.length-1 ;x++ ) {
System.out.print(arr[x]+" ");
}
}
}
|
|