first commit
This commit is contained in:
BIN
TP_DEV3.2/Genericite/Exo1.class
Normal file
BIN
TP_DEV3.2/Genericite/Exo1.class
Normal file
Binary file not shown.
69
TP_DEV3.2/Genericite/Exo1.java
Normal file
69
TP_DEV3.2/Genericite/Exo1.java
Normal file
@@ -0,0 +1,69 @@
|
||||
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||
|
||||
|
||||
|
||||
public class Exo1 {
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
List<Integer> liste1 = new ArrayList<>();
|
||||
liste1.add(9);
|
||||
liste1.add(1);
|
||||
|
||||
|
||||
|
||||
List<Number> liste2 = new ArrayList<>();
|
||||
liste2.add(15);
|
||||
liste2.add(1.5f);
|
||||
liste2.add(15000L);
|
||||
|
||||
|
||||
List<Float> liste3 = new ArrayList<>();
|
||||
liste3.add(3.93f);
|
||||
liste3.add(3.07f);
|
||||
|
||||
System.out.println("liste 1 (Integer) ="+ liste1);
|
||||
System.out.println("liste 2 (Number) ="+ liste2);
|
||||
System.out.println("liste 3 (Float) ="+ liste3);
|
||||
|
||||
|
||||
liste2.addAll(liste1);
|
||||
liste2.addAll(liste3);
|
||||
|
||||
System.out.println("Apres versement des liste 1 et 3 dans la 2" + liste2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
TP_DEV3.2/Genericite/Exodeux.class
Normal file
BIN
TP_DEV3.2/Genericite/Exodeux.class
Normal file
Binary file not shown.
83
TP_DEV3.2/Genericite/Exodeux.java
Normal file
83
TP_DEV3.2/Genericite/Exodeux.java
Normal file
@@ -0,0 +1,83 @@
|
||||
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||
|
||||
public class Exodeux {
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
|
||||
|
||||
AfficherTouslesArgs(args);
|
||||
AfficherLes5erArgs(args);
|
||||
trierEtAfficherNaturel(args);
|
||||
trierEtAffiicherSansCasse(args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void AfficherTouslesArgs(String[] arguments){
|
||||
|
||||
|
||||
String TousLesArgsTransforme = Arrays.toString(arguments);
|
||||
System.out.println("Voici tous les args " + TousLesArgsTransforme);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void AfficherLes5erArgs(String[] arguments) {
|
||||
|
||||
int limite = Math.min(5, arguments.length);
|
||||
String[] premier = Arrays.copyOf(arguments,limite);
|
||||
System.out.println("Voici les 5er arguments : "+Arrays.toString(premier));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void trierEtAfficherNaturel(String[] args) {
|
||||
|
||||
|
||||
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||
|
||||
Arrays.sort(copyArgument);
|
||||
|
||||
String NaturelTriage = Arrays.toString(copyArgument);
|
||||
|
||||
System.out.println("Tri naturel" + NaturelTriage);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void trierEtAffiicherSansCasse(String[] args){
|
||||
|
||||
|
||||
|
||||
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||
Arrays.sort(copyArgument,String::compareToIgnoreCase);
|
||||
String SansCasseTrierNickelChrome = Arrays.toString(copyArgument);
|
||||
System.out.println("Tri sans casse naturel : "+ SansCasseTrierNickelChrome);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
@@ -0,0 +1,106 @@
|
||||
public class Exotrois {
|
||||
|
||||
|
||||
public static <T> plusFrequent(T[] tableau){
|
||||
|
||||
|
||||
T valeurGagnante = tableau[0];
|
||||
int frequenceGagnante = 0;
|
||||
int premierIndexGagnant = tableau.length;
|
||||
|
||||
|
||||
|
||||
for(int i=0;i<tableau.length; i++){
|
||||
|
||||
|
||||
|
||||
T valeurCourante = tableau[i];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int frequenceCourante =0;
|
||||
for(int k=0; k<tableau.length; k++){
|
||||
|
||||
if(Object.equals(tableau[k], valeurCourante)){
|
||||
|
||||
frequenceCourante++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
int premierIndexCourant = -1;
|
||||
for(int j=0; j<tableau.length; j++){
|
||||
|
||||
if(Object.equals(tableau[j]), valeurCourante){
|
||||
|
||||
premierIndexCourant=j;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user