a104: 排序
題目:http://zerojudge.tw/ShowProblem?problemid=a104
程式碼:
import java.util.Scanner;
public class a104 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int a = sc.nextInt();
int[] b = new int [a];
for(int i=0;i<a;i++){
b[i] = sc.nextInt();
}
for(int i=0;i<a;i++){
for(int j=0;j<a;j++){
if(b[i]<b[j]){
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
}
for(int arr : b){
System.out.print(arr+" ");
}
System.out.println("");
}
}
}

留言
張貼留言