Bonjour,
je dois faire une méthode dans la classe Tableau qui me permette de trié un tableau avec des entiers pris au hasard et de les mettre dans un ordre croissant avec un tri par minimum.
Quand je compile j'obtiens "Tableau trié : 2@5hk9z6m3.
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
43
44
45
46
47
48
49
50
51
52
53 public class tableaux { protected static int[] tab; public tableaux(int taille) { int max = 99; taille = 10; tab = new int[taille]; for (int i = 0; i < taille; i++) { tab[i] = (int) (Math.random() * (max)) + 1; tab[i]++; } } public void afficheTableau() { for (int i = 0; i < 10; i++) { tab[i]++; Terminal.ecrireIntln(tab[i]); } } public int[] triMinimum() { int debut = tab[0]; int posMin = debut; for (int i = debut + 1; i < tab.length - 2; i++) { posMin = i; for (int j = i + 1; j <= tab.length - 1; j++) { if (tab[j] < tab[posMin]) { posMin = j; } } int tampon = tab[i]; tab[i] = tab[posMin]; tab[posMin] = tampon; } Terminal.ecrireStringln("Tableau trié : "+tab); return tab; } public static void main(String[] args) { tableaux tab1 = new tableaux(12); tab1.afficheTableau(); tab1.triMinimum(); } }
Partager