septembre + octobre
This commit is contained in:
BIN
DEV/DEV3.2/TP02_Recursivite/Q1Factoriel.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q1Factoriel.class
Normal file
Binary file not shown.
32
DEV/DEV3.2/TP02_Recursivite/Q1Factoriel.java
Normal file
32
DEV/DEV3.2/TP02_Recursivite/Q1Factoriel.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.lang.*;
|
||||
|
||||
public class Q1Factoriel{
|
||||
int tour;
|
||||
public Q1Factoriel(){
|
||||
tour = -1;
|
||||
}
|
||||
public long factoriel(long n) {
|
||||
this.tour ++;
|
||||
this.espace(n);
|
||||
if (n < 0){
|
||||
return -1;
|
||||
}
|
||||
if (n < 2){
|
||||
//Thread.dumpStack();
|
||||
this.espace(1);
|
||||
this.tour --;
|
||||
return 1;
|
||||
}
|
||||
long resultat = n*factoriel(n-1);
|
||||
this.espace(resultat);
|
||||
this.tour --;
|
||||
return resultat;
|
||||
}
|
||||
|
||||
public void espace(long txt){
|
||||
for (int i=0; i<this.tour; i++){
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println(txt);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q1Main.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q1Main.class
Normal file
Binary file not shown.
15
DEV/DEV3.2/TP02_Recursivite/Q1Main.java
Normal file
15
DEV/DEV3.2/TP02_Recursivite/Q1Main.java
Normal file
@@ -0,0 +1,15 @@
|
||||
public class Q1Main{
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
long n = Long.parseLong(args[0]);
|
||||
Q1Factoriel calcul = new Q1Factoriel();
|
||||
System.out.println(calcul.factoriel(n));
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
System.out.println("erreur argument");
|
||||
}
|
||||
catch(ArrayIndexOutOfBoundsException e){
|
||||
System.out.println("erreur argument");
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q2Main.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q2Main.class
Normal file
Binary file not shown.
14
DEV/DEV3.2/TP02_Recursivite/Q2Main.java
Normal file
14
DEV/DEV3.2/TP02_Recursivite/Q2Main.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class Q2Main{
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
Q2Modele calcul = new Q2Modele(args);
|
||||
calcul.printInt(0);
|
||||
System.out.println("nombre de paire = " + calcul.getPaire());
|
||||
System.out.println("plus grand = " + calcul.getMax());
|
||||
calcul.printInv(0);
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
System.out.println("erreur argument");
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q2Modele.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q2Modele.class
Normal file
Binary file not shown.
73
DEV/DEV3.2/TP02_Recursivite/Q2Modele.java
Normal file
73
DEV/DEV3.2/TP02_Recursivite/Q2Modele.java
Normal file
@@ -0,0 +1,73 @@
|
||||
public class Q2Modele{
|
||||
private String[] tabString;
|
||||
private int[] tabInt;
|
||||
private int paire;
|
||||
private int max;
|
||||
|
||||
public Q2Modele(String[] tableau){
|
||||
this.tabString = tableau;
|
||||
this.tabInt = new int[this.tabString.length];
|
||||
this.stringToInt(0);
|
||||
this.paire = 0;
|
||||
this.max = 0;
|
||||
}
|
||||
private void stringToInt(int i) {
|
||||
if (i>=0 && i < this.tabString.length){
|
||||
this.tabInt[i] = Integer.parseInt(this.tabString[i]);
|
||||
stringToInt(i+1);
|
||||
}
|
||||
}
|
||||
public void printInt(int i) {
|
||||
if (i>=0 && i < this.tabInt.length-1){
|
||||
System.out.print(this.tabInt[i] + " ");
|
||||
printInt(i+1);
|
||||
}
|
||||
if (i == this.tabInt.length-1){
|
||||
System.out.println(this.tabInt[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void printInv(int i) {
|
||||
if (i>=0 && i < this.tabInt.length-1){
|
||||
System.out.print(this.tabInt[this.tabInt.length-i-1] + " ");
|
||||
printInt(i+1);
|
||||
}
|
||||
if (i == this.tabInt.length-1){
|
||||
System.out.println(this.tabInt[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void paire(int i) {
|
||||
if (i==0){
|
||||
this.paire = 0;
|
||||
}
|
||||
if (i>=0 && i < this.tabInt.length){
|
||||
if (this.tabInt[i]%2 == 0){
|
||||
this.paire ++;
|
||||
}
|
||||
paire(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
private void max(int i) {
|
||||
if (i==0){
|
||||
this.max = 0;
|
||||
}
|
||||
if (i>=0 && i < this.tabInt.length){
|
||||
if (this.tabInt[i] > this.max){
|
||||
this.max = this.tabInt[i];
|
||||
}
|
||||
max(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPaire(){
|
||||
paire(0);
|
||||
return this.paire;
|
||||
}
|
||||
|
||||
public int getMax(){
|
||||
max(0);
|
||||
return this.max;
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q3Fibonacci.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q3Fibonacci.class
Normal file
Binary file not shown.
36
DEV/DEV3.2/TP02_Recursivite/Q3Fibonacci.java
Normal file
36
DEV/DEV3.2/TP02_Recursivite/Q3Fibonacci.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import java.lang.*;
|
||||
|
||||
public class Q3Fibonacci{
|
||||
int tour;
|
||||
public Q3Fibonacci(){
|
||||
tour = -1;
|
||||
}
|
||||
public int fibonacci(int n) {
|
||||
this.tour ++;
|
||||
this.espace(n);
|
||||
if (n < 0){
|
||||
return -1;
|
||||
}
|
||||
if (n == 0){
|
||||
this.espace(0);
|
||||
this.tour --;
|
||||
return 0;
|
||||
}
|
||||
if (n == 1){
|
||||
this.espace(1);
|
||||
this.tour --;
|
||||
return 1;
|
||||
}
|
||||
int resultat = fibonacci(n-2) + fibonacci(n-1);
|
||||
this.espace(resultat);
|
||||
this.tour --;
|
||||
return resultat;
|
||||
}
|
||||
|
||||
private void espace(int txt){
|
||||
for (int i=0; i<this.tour; i++){
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println(txt);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q3Main.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q3Main.class
Normal file
Binary file not shown.
15
DEV/DEV3.2/TP02_Recursivite/Q3Main.java
Normal file
15
DEV/DEV3.2/TP02_Recursivite/Q3Main.java
Normal file
@@ -0,0 +1,15 @@
|
||||
public class Q3Main{
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
int i = Integer.parseInt(args[0]);
|
||||
Q3Fibonacci calcul = new Q3Fibonacci();
|
||||
calcul.fibonacci(i);
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
System.out.println("erreur argument");
|
||||
}
|
||||
catch(ArrayIndexOutOfBoundsException e){
|
||||
System.out.println("erreur argument");
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Main.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Main.class
Normal file
Binary file not shown.
24
DEV/DEV3.2/TP02_Recursivite/Q5Main.java
Normal file
24
DEV/DEV3.2/TP02_Recursivite/Q5Main.java
Normal file
@@ -0,0 +1,24 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.Polygon;
|
||||
|
||||
public class Q5Main{
|
||||
public static void main(String[] args) {
|
||||
|
||||
JFrame fenetre = new JFrame("Q1 Galerie");
|
||||
fenetre.setSize(300, 200);
|
||||
fenetre.setLocation(700, 300);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Polygon etoile = new Polygon();
|
||||
etoile.addPoint(50,50);
|
||||
etoile.addPoint(300,140);
|
||||
etoile.addPoint(230,80);
|
||||
etoile.addPoint(10,330);
|
||||
fenetre.setVisible(true);
|
||||
|
||||
Q5Polygon dessinEtoile = new Q5Polygon(etoile);
|
||||
fenetre.add(dessinEtoile);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Polygon.class
Normal file
BIN
DEV/DEV3.2/TP02_Recursivite/Q5Polygon.class
Normal file
Binary file not shown.
16
DEV/DEV3.2/TP02_Recursivite/Q5Polygon.java
Normal file
16
DEV/DEV3.2/TP02_Recursivite/Q5Polygon.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.*;
|
||||
|
||||
public class Q5Polygon extends JComponent {
|
||||
public Polygon etoile;
|
||||
|
||||
public Q5Polygon(Polygon etoile){
|
||||
this.etoile = etoile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
pinceau.setColor(Color.BLUE);
|
||||
pinceau.fillPolygon(this.etoile);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user