参考代码:
import java.util.Scanner; public class Main13 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //给定一个长度为n的数列,将这个数列按从小到大的顺序排列。1<=n<=200 Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int [] s=new int[a]; for (int i = 0; i < s.length; i++) { s[i]=scanner.nextInt(); } for (int k = 0; k < s.length-1; k++) { for (int j = 0; j < s.length-1-k; j++) { if (s[j]>s[j+1]) { int num=s[j]; s[j]=s[j+1]; s[j+1]=num; } } } for (int i = 0; i < s.length; i++) { System.out.print(s[i]+" "); } } }
0.0分
1 人评分