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
| import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class TriNombre {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Entrez le nombre de valeurs que vous voulez trier.");
int n = sc.nextInt();
int[] tab = new int[n];
int a = 0;
for (a = 0; a < tab.length; a++) {
Random random = new Random();
tab[a] = random.nextInt();
}
String representationDuTab = Arrays.toString(tab);
System.out.println(representationDuTab);
int b = n;
int c;
int min;
for (int i = 0; i < b - 1; i++) {
min = i;
for (c = i + 1; c < b; c++) {
if (tab[c] < tab[min])
min = c;
}
if (min != i) {
int temp = tab[min];
tab[min] = tab[i];
tab[i] = temp;
}
}
for (c = 0; c < b; c++) {
System.out.print(tab[c] + " ");
}
sc.close();
}
} |