1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import java.util.*;
public class triabulle{
public static void sort(Comparable[]tab){
boolean b=false;
while(b==false){
b=true;
for(int i=0; i<tab.length-1; i++){
if(tab[i+1].compareTo(tab[i])<0){
Comparable aux=tab[i];
tab[i]=tab[i+1];
tab[i+1]=aux;
b=false;
}
}
}
}
public static void main (String[]args){
Double[]x={new Double(12.5), new Double(3.0), new Double(-2.1), new Double(4),new Double(0.25), new Double(10), new Double (5.2)};
sort(x);
for(int i=0; i<x.length; i++){
System.out.println(x[i]+" ");
}
}
} |