diff --git a/DEV3.2/TP02/01_Appels/Factorielle.class b/DEV3.2/TP02/01_Appels/Factorielle.class new file mode 100644 index 0000000..39f593a Binary files /dev/null and b/DEV3.2/TP02/01_Appels/Factorielle.class differ diff --git a/DEV3.2/TP02/01_Appels/Factorielle.java b/DEV3.2/TP02/01_Appels/Factorielle.java new file mode 100644 index 0000000..3d16dee --- /dev/null +++ b/DEV3.2/TP02/01_Appels/Factorielle.java @@ -0,0 +1,17 @@ +public class Factorielle { + + public static int factorielle(int n, int indentation) { + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur de n : " + n); + if (n == 1) { + return 1; + } + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur renvoyée : " + n + factorielle(n - 1, indentation++)); + return n * factorielle(n - 1, indentation++); + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/01_Appels/Main.class b/DEV3.2/TP02/01_Appels/Main.class new file mode 100644 index 0000000..41fc166 Binary files /dev/null and b/DEV3.2/TP02/01_Appels/Main.class differ diff --git a/DEV3.2/TP02/01_Appels/Main.java b/DEV3.2/TP02/01_Appels/Main.java new file mode 100644 index 0000000..10faf2a --- /dev/null +++ b/DEV3.2/TP02/01_Appels/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println(Integer.parseInt(args[0]) + "! = " + Factorielle.factorielle(Integer.parseInt(args[0]), 0)); + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/02_Tableaux/Main.class b/DEV3.2/TP02/02_Tableaux/Main.class new file mode 100644 index 0000000..f48d151 Binary files /dev/null and b/DEV3.2/TP02/02_Tableaux/Main.class differ diff --git a/DEV3.2/TP02/02_Tableaux/Main.java b/DEV3.2/TP02/02_Tableaux/Main.java new file mode 100644 index 0000000..3478f4f --- /dev/null +++ b/DEV3.2/TP02/02_Tableaux/Main.java @@ -0,0 +1,17 @@ +import java.util.Arrays; + +public class Main { + public static void main(String[] args) { + Tableaux t = new Tableaux(args.length); + + int[] entiers = t.convertitTab(args, args.length); + + t.afficheTab(entiers, 0); + + System.out.println("Nombre d'entiers pairs : " + t.entiersPairs(0)); + System.out.println("Valeur maximale : " + t.maximum(0, 0)); + + t.afficheTabInverse(entiers, entiers.length-1); + + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/02_Tableaux/Tableaux.class b/DEV3.2/TP02/02_Tableaux/Tableaux.class new file mode 100644 index 0000000..30cc23f Binary files /dev/null and b/DEV3.2/TP02/02_Tableaux/Tableaux.class differ diff --git a/DEV3.2/TP02/02_Tableaux/Tableaux.java b/DEV3.2/TP02/02_Tableaux/Tableaux.java new file mode 100644 index 0000000..250ad56 --- /dev/null +++ b/DEV3.2/TP02/02_Tableaux/Tableaux.java @@ -0,0 +1,61 @@ +public class Tableaux { + + private int[] tableau; + + public Tableaux(int tailleTab) { + this.tableau = new int[tailleTab]; + } + + public int[] convertitTab(String[] tab, int tailleTab) { + if (tailleTab == 1) { + this.tableau[0] = Integer.parseInt(tab[0]); + return this.tableau; + } + this.tableau[tailleTab-1] = Integer.parseInt(tab[tailleTab-1]); + return this.convertitTab(tab, --tailleTab); + } + + public void afficheTab(int[] tab, int increment) { + if (increment == tab.length-1) { + System.out.println(tab[increment]); + } else { + System.out.print(tab[increment] + " | "); + afficheTab(tab, ++increment); + } + + } + + public int entiersPairs(int increment) { + if (increment == this.tableau.length) { + return 0; + } + if (this.tableau[increment] % 2 == 0) { + return 1 + entiersPairs(++increment); + } else { + return 0 + entiersPairs(++increment); + } + } + + public int maximum(int increment, int maxActuel) { + if (increment == this.tableau.length-1) { + if (this.tableau[increment] > maxActuel) { + return this.tableau[increment]; + } + return maxActuel; + } + if (this.tableau[increment] > maxActuel) { + return this.maximum(increment+1, this.tableau[increment]); + } + return this.maximum(increment+1, maxActuel); + + } + + public void afficheTabInverse(int[] tab, int decrement) { + if (decrement == 0) { + System.out.println(tab[0]); + } else { + System.out.print(tab[decrement] + " | "); + afficheTabInverse(tab, --decrement); + } + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/03_Fibonacci/Fibonacci.class b/DEV3.2/TP02/03_Fibonacci/Fibonacci.class new file mode 100644 index 0000000..d04cc38 Binary files /dev/null and b/DEV3.2/TP02/03_Fibonacci/Fibonacci.class differ diff --git a/DEV3.2/TP02/03_Fibonacci/Fibonacci.java b/DEV3.2/TP02/03_Fibonacci/Fibonacci.java new file mode 100644 index 0000000..68dd0df --- /dev/null +++ b/DEV3.2/TP02/03_Fibonacci/Fibonacci.java @@ -0,0 +1,27 @@ +public class Fibonacci { + + public static int fibonacci(int n, int indentation) { + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur de n : " + n); + if (n == 0) { + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur de retour : " + 0); + return 0; + } if (n == 1) { + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur de retour : " + 1); + return 1; + } + for (int i = 0; i != indentation; i++) { + System.out.print(" "); + } + System.out.println("Valeur de retour : " + fibonacci(n-2, ++indentation) + fibonacci(n-1, ++indentation)); + return fibonacci(n-2, ++indentation) + fibonacci(n-1, ++indentation); + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/03_Fibonacci/Main.class b/DEV3.2/TP02/03_Fibonacci/Main.class new file mode 100644 index 0000000..7dfbcbd Binary files /dev/null and b/DEV3.2/TP02/03_Fibonacci/Main.class differ diff --git a/DEV3.2/TP02/03_Fibonacci/Main.java b/DEV3.2/TP02/03_Fibonacci/Main.java new file mode 100644 index 0000000..4f7f61b --- /dev/null +++ b/DEV3.2/TP02/03_Fibonacci/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + System.out.println(Fibonacci.fibonacci(Integer.parseInt(args[0]), 0)); + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/05_Flocon/Fenetre.java b/DEV3.2/TP02/05_Flocon/Fenetre.java new file mode 100644 index 0000000..3848440 --- /dev/null +++ b/DEV3.2/TP02/05_Flocon/Fenetre.java @@ -0,0 +1,20 @@ +import java.awt.*; +import javax.swing.*; + +public class Fenetre extends JFrame { + + private int ordre; + + public Fenetre(int ordre) { + this.ordre = ordre; + + this.setSize(500, 500); + this.setLocation(100, 100); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + this.setLayout(new GridLayout(1, 1)); + this.add(new JFlocon(ordre)); + } + + +} \ No newline at end of file diff --git a/DEV3.2/TP02/05_Flocon/JFlocon.java b/DEV3.2/TP02/05_Flocon/JFlocon.java new file mode 100644 index 0000000..a4f6e3d --- /dev/null +++ b/DEV3.2/TP02/05_Flocon/JFlocon.java @@ -0,0 +1,23 @@ +import java.awt.*; +import javax.swing.*; + +public class JFlocon extends JComponent { + + private int ordre; + + public JFlocon(int ordre) { + this.ordre = ordre; + } + + @Override + public void paintComponent(Graphics pinceau) { + Graphics secondPinceau = pinceau.create(); + + if (this.isOpaque()) { + this.setColor(this.getBackgroundColor()); + this.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + + } +} \ No newline at end of file diff --git a/DEV3.2/TP02/05_Flocon/Main.java b/DEV3.2/TP02/05_Flocon/Main.java new file mode 100644 index 0000000..64b82fa --- /dev/null +++ b/DEV3.2/TP02/05_Flocon/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + Fenetre fenetre = new Fenetre(Integer.parseInt(args[0])); + fenetre.setVisible(true); + } +} \ No newline at end of file