This commit is contained in:
Simoes Lukas
2025-10-02 12:22:53 +02:00
parent be5ef16034
commit 56258c01e6
12 changed files with 132 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,27 @@
import java.util.ArrayList;
public class Frequence {
public static <T> T frequence(T[] tab) {
ArrayList<T> cles = new ArrayList<>();
ArrayList<Integer> valeurs = new ArrayList<>();
for (int i = 0; i != tab.length; i++) {
if (!cles.contains(tab[i])) {
cles.add(tab[i]);
valeurs.add(0);
}
valeurs.add(cles.indexOf(tab[i]), (valeurs.get(cles.indexOf(tab[i])) + 1));
}
int max = valeurs.get(0);
for (int i = 0; i != valeurs.size(); i++) {
if (valeurs.get(i) > max) {
max = valeurs.get(i);
}
}
return cles.get(valeurs.indexOf(max));
}
}

Binary file not shown.

View File

@@ -0,0 +1,16 @@
import javax.swing.JLabel;
public class Main {
public static void main(String[] args) {
JLabel[] tab = new JLabel[5];
tab[0] = new JLabel("OK");
tab[1] = new JLabel("KO");
tab[2] = new JLabel("WOW");
tab[3] = new JLabel("LE NOMBRE LA");
tab[4] = new JLabel("OK");
System.out.println(Frequence.frequence(args));
System.out.println(Frequence.frequence(tab).getText());
}
}