简单写了一下:
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入:数字以',' 隔开");
String str = sc.next();
String [] array1 = str.split(",");
for (int i = 0; i < array1.length; i++) {
int a1 = Integer.parseInt(array1[i]);
int max = a1,index =i;;
for (int j = i+1; j < array1.length; j++) {
int a2 = Integer.parseInt(array1[j]);
if (a2>max) {
max=a2;index=j;
}
}
array1[i]=max+"";
array1[index]=a1+"";
}
System.out.println("排序后:");
for (int i = 0; i < array1.length; i++) {
System.out.print(array1[i]+"");
}
}
}
public class Test {
public static void main(String[] agrs){
int temp = 0;
int[] a = { 随便输入几个数 用,来分开};
for(int i=0;i
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int i=0; i
}
}