冒泡排序,慢慢来,我是新来的小白。
import java.util.Arrays;
import java.util.Scanner;
public class java26Print {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入三个数:");
int s1 = sc.nextInt();
int s2 = sc.nextInt();
int s3 = sc.nextInt();
/*
int []arr={s1,s2,s3};
Arrays.sort(arr);//集合排序
System.out.println(Arrays.toString(arr));
*/
//冒泡排序
int[] arr = {s1, s2, s3};
for (int i = 0; i <arr.length-1 ; i++) {//外层循环控制排序趟数(n-1)趟
for (int j = 0; j < arr.length-1-i; j++) {//内层循环控制每一趟要排序多少次
int n;
if (arr[j] > arr[j+1]) {
n = arr[j];
arr[j] = arr[j+1];
arr[j+1] = n;
}
}
System.out.println("从小到大排序:");
for (int j = 0; j <arr.length ; j++) {
System.out.println(arr[j]);
}
}
}
}