解题思路:利用冒泡排序方法,
注意事项:
参考代码:
package lianxi;
import java.util.Scanner;
public class 排序 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=0;
while (sc.hasNext()){
int n=sc.nextInt();
int [] a =new int[n];
for (int i = 0; i <a.length ; i++) {
a[i]=sc.nextInt();
}
for (int i = 0; i <a.length-1 ; i++) {
for (int j = 0; j <a.length-1-i; j++) {
if(a[j]>a[j+1])
{t=a[j];
a[j]=a[j+1];
a[j+1]=t;}
}
}
for (int i = 0; i <a.length ; i++)
System.out.print(a[i]+" ");
System.out.println();
}
}
}
0.0分
1 人评分
A+B for Input-Output Practice (IV) (C语言代码)浏览:508 |
C语言训练-排序问题<1> (C语言代码)浏览:355 |
小O的数字 (C++代码)浏览:763 |
C二级辅导-计负均正 (C语言代码)浏览:643 |
C语言训练-最大数问题 (C语言代码)浏览:591 |
简单的a+b (C语言代码)浏览:454 |
Tom数 (Java代码)浏览:594 |
Manchester- 求之N内的素数浏览:1495 |
哥德巴赫曾猜测 (C++代码)浏览:740 |
Manchester- A+B for Input-Output Practice (II)浏览:1318 |