12 Octobre

This commit is contained in:
Adrian POURCHOT 2023-10-12 12:26:02 +02:00
parent 22b6d39736
commit 87fa32a945
9 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import java.awt.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
ArrayList<Integer> ListI = new ArrayList<Integer>();
ArrayList<Float> ListF = new ArrayList<Float>();
ArrayList<Number> ListN = new ArrayList<Number>();
int I = 3;
Float F = 5.27f;
Long L = 555165l;
ListI.add(I);
ListI.add(F);
ListI.add(L);
ListF.add(I);
ListF.add(F);
ListF.add(L);
ListN.add(I);
ListN.add(F);
ListN.add(L);
}
}

View File

@ -0,0 +1,3 @@
a) La liste integer ne peut pas recevoir de float ni de long et la liste float ne peut recevoir ni int ni long.
b) La liste Number pourra recevoir la liste Integer et Float.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,21 @@
import java.awt.*;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
public class Main{
public static void main(String[] args) {
// Tri avec un comparateur de chaînes
Arrays.sort(args, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareTo(s2);
}
});
// Afficher le tableau trié
System.out.println(Arrays.toString(args));
}
}

BIN
DEV3.2/TP2/Appels.class Normal file

Binary file not shown.

30
DEV3.2/TP2/Appels.java Normal file
View File

@ -0,0 +1,30 @@
public class Appels {
public static int indentation;
public static long fact(long n){
for (int i = 0; i < indentation; i++) {
System.out.print(" ");
}
System.out.println("Argument début: "+n);
indentation++;
if(n==1l){
//Thread.dumpStack();
return 1;
}else{
long r=n*fact(n-1l);
for (int i = 0; i < indentation-1; i++) {
System.out.print(" ");
}
indentation--;
System.out.println("Argument fin: "+r);
return r;
}
}
public static void main(String args[]){
long x=Long.parseLong(args[0]);
indentation=0;
System.out.println(x+"! = "+fact(x));
}
}

BIN
DEV3.2/TP2/Tableaux.class Normal file

Binary file not shown.

83
DEV3.2/TP2/Tableaux.java Normal file
View File

@ -0,0 +1,83 @@
public class Tableaux{
public static int[] RemplisTableaux(String[] arguments, int val, int[] tab){
if (val == (arguments.length-1)){
tab[val]=Integer.parseInt(arguments[val]);
return tab;
}else{
tab[val]=Integer.parseInt(arguments[val]);
return RemplisTableaux(arguments, val+1, tab);
}
}
public static int AfficheTableaux(int[] tab, int val){
if (val == (tab.length-1)){
System.out.println(tab[val]+" ");
return 0;
}else{
System.out.print(tab[val]+" ");
return AfficheTableaux(tab, val+1);
}
}
public static int EntierPairs(int[] tab, int val, int pair){
if (val == (tab.length-1)){
if ((tab[val]%2)==0){
pair++;
return pair;
}else{
return pair;
}
}else{
if ((tab[val]%2)==0){
return EntierPairs(tab, val+1, pair+1);
}else{
return EntierPairs(tab, val+1, pair);
}
}
}
public static int Maximum(int[] tab, int val, int maxi){
if (val == (tab.length-1)){
if (tab[val]>maxi){
return tab[val];
}else{
return maxi;
}
}else{
if (tab[val]>maxi){
return Maximum(tab, val+1, tab[val]);
}else{
return Maximum(tab, val+1, maxi);
}
}
}
public static int[] InverseTableaux(int[] tab, int val){
if (val == ((tab.length/2)-1)){
int temp=tab[val];
tab[val]=tab[(tab.length-1)-val];
tab[(tab.length-1)-val]=temp;
return tab;
}else{
int temp=tab[val];
tab[val]=tab[(tab.length-1)-val];
tab[(tab.length-1)-val]=temp;
return InverseTableaux(tab, val+1);
}
}
public static void main(String args[]){
int i=0;
int longueur=args.length;
int[] tab=new int[longueur];
tab = RemplisTableaux(args, 0, tab);
AfficheTableaux(tab, 0);
int p = EntierPairs(tab, 0, 0);
System.out.println("Le tableau contient "+p+" nombre pair.");
int m = Maximum(tab, 0, 0);
System.out.println("Le plus grand chiffre du tableau est: "+m);
tab = InverseTableaux(tab, 0);
AfficheTableaux(tab, 0);
}
}