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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
import java.util.Arrays;
import java.util.stream.Collectors;
public class Test {
static String [] tabNoms = {"Batman","Donald","Kipsang","Luigi","Mario","OuiOui","Robin","Sonic","Zorro"};
static int[] tabTemps = {140,360,123,190,150,340,135,90,200};
static int[] tabTempsTries = new int[tabTemps.length];
static String [] tabNomsTries = new String[tabNoms.length];
static String [] podium = new String[3]; // 3 car ne gère pas les ex æquo
public static void main(String[] args) {
tabTempsTries= Arrays.stream(tabTemps).sorted().toArray();
Arrays.stream(tabTempsTries).forEach(System.out::println);
// ou
System.arraycopy(tabTemps,0,tabTempsTries,0,tabTemps.length);
Arrays.sort(tabTempTries);
Arrays.stream(tabTempsTries).forEach(System.out::println); // affiche le résultat
Arrays.stream(tabTempsTries).map(s-> Test.indice(s)).mapToObj(s-> tabNoms[s]).collect(Collectors.toList()).toArray(tabNomsTries);
Arrays.stream(tabNomsTries).forEach(System.out::println);
//ou
tabNomsTries = Test.triParNom(tabtemps,tabnoms);
Arrays.stream(tabNomsTries).forEach(System.out::println);
// podium : ne gère pas les ex æquo
podium = Test.podium(tabNomsTries);
Arrays.stream(podium).forEach(System.out::println);
}
static int indice(int valeur){
int i = 0;
for ( i = 0; !(( tabTemps[i] == valeur) || i> tabTempsTries.length) ; i++){
}
return i;
}
static String[] triParNom(final int[] tabTemps, final String[] tabNoms){
String [] tabres = new String[tabNoms.length];
int j=0;
int [] tabTempsTrie = Arrays.stream(tabTemps).sorted().toArray();
for (int i = 0; i< tabTempsTrie.length ; i++){
for (j = 0; !((tabTempsTrie[i] == tabTemps[j]) || j> tabTemps.length) ;j++){
}
tabres[i] = tabNoms[j];
}
return tabres;
}
static String[] podium(final String[] tabData){
String[] podium= new String[3];
System.arraycopy(tabData,0,podium,0,3);
return podium;
}
} |
Partager