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
| public class Exemple {
private static int[] NUMBER_ARRAY = { 0, 32, 15, 19, 4, 21, 2, 25, 17, 34, 6, 27, 13, 36, 11, 30, 8, 23, 10, 5, 24,
16, 33, 1, 20, 14, 31, 9, 22, 18, 29, 7, 28, 12, 35, 3, 26 };
public static void main(String[] args) {
int nombre = 26;
int positionNombre = positionNombre(nombre);
int[] adroite = new int[9];
for(int i=0; i<adroite.length; i++) {
adroite[i] = NUMBER_ARRAY[(positionNombre+1+i)%NUMBER_ARRAY.length];
}
System.out.println("À droite : " + Arrays.toString(adroite));
int[] agauche = new int[9];
for(int i=0; i<agauche.length; i++) {
agauche[i] = NUMBER_ARRAY[(positionNombre-1-i)%NUMBER_ARRAY.length];
}
System.out.println("À gauche : " + Arrays.toString(agauche));
}
private static int positionNombre(int nombre) {
for(int i=0; i<NUMBER_ARRAY.length; i++) {
if ( NUMBER_ARRAY[i]==nombre ) {
return i;
}
}
throw new IllegalArgumentException("Nombre "+nombre+" introuvable.");
}
} |
Partager