Bonjour,

Je souhaite créer une classe qui me permet de choisir au hazard 4 chiffres compris entre 1 et 6 inclus. Une fois le code à 4 chiffres trouvé je souhaite l'insérer dans un tableau.

Cependant mon tableau m'affiche tout le temps 0 pour les 4 variables quand je tente de l'afficher. Pour l'instant tout est en static car je cherche juste à tester ma classe mais plus tard je voudrais utiliser le code dans une autre classe.

Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
    class Code
   {
   // -- Creation des variables
      static int a;
      static int b;
      static int c;
      static int d;
 
   // -- Creation d'un tableau
      static int[] monTableau = {a, b, c, d};
 
   // -- Creation et initialisation des extrêmes pour le code au hazard
      static int minimum = 1;
      static int maximum = 7;
 
   // -- Creation des différents random
      static int random = (int)(Math.random() * (maximum-minimum)) + minimum;
      static int random2 = (int)(Math.random() * (maximum-minimum)) + minimum;
      static int random3 = (int)(Math.random() * (maximum-minimum)) + minimum;
      static int random4 = (int)(Math.random() * (maximum-minimum)) + minimum;
 
   // -- Couleur 1=Rose 2=Orange 3=Bleu 4=Vert 5=Jaune 6=Rouge
       public static void main(String[] args)
      {
         a = random;
         //System.out.println("    a = "+a);
 
         b = random2;
         //System.out.println("    b = "+b);
 
         c = random3;
         //System.out.println("    c = "+c);
 
         d = random4;
         //System.out.println("    d = "+d);
 
         for(int k=0; k<monTableau.length; k++)
 
            System.out.println(" le tableau monTableau = " + monTableau[k]);
      }
   }
Merci de m'éclairer.