import java.util.Scanner; public class CompteEstBon { int [] nombres; //tableau contenant les 6 nombres passés en entrée int res_demande; // résultat demandé int r; // résultat de l'opération int z; // étape int compteur; // compteur du nombre d'appels récursifs int m1[], m2[], si[], sj[]; char ope[], sop[]; int [] tab1; int [] tab2; int [] tab3; int [] tab4; int k, ss1, ss2, ss3; String [] resultat; boolean op1, op2, op3, op4; public CompteEstBon() { nombres = new int[6]; m1 = new int [5]; m2 = new int [5]; ope = new char [5]; si = new int [5]; sj = new int[5]; sop = new char[5]; z=0; ss2 = 2147483647; } public void saisie() { System.out.println("Entrer la liste des 6 nombres : "); Scanner sc = new Scanner(System.in); for(int i=0; i<6; i++) { nombres[i] = sc.nextInt(); } System.out.println("Entrer le résultat demandé : "); res_demande = sc.nextInt(); //for(int i=0; ir?r-res_demande:res_demande-r; if(kz)) { System.arraycopy(m1,0,si,0,5); System.arraycopy(m2,0,sj,0,5); System.arraycopy(ope,0,sop,0,5); ss1=z; } } /** * Méthode de tri décroissant d'un tableau d'entiers * @param t tableau à trier */ public static void triDec(int [] t) { int taille, tmp; taille = t.length; while(taille>1){ for(int i=0; i0)&&(j>0)){ r = i+j; m1[z] = i; m2[z] = j; ope[z] = '+'; sauve(); return true; } return false; } /** * Méthode vérifiant que la soustraction est possible entre deux entiers et qui effectue l'opération * @param i entier * @param j entier * @return boolean true si l'opération a été effectuée */ public boolean sous(int i,int j){ if((j>0)&&(j>1)){ r = i-j; //if(r!=j){ ope[z]='-'; m1[z]=i; m2[z]=j; sauve(); return true; } //} return false; } /** * Méthode vérifiant que la multiplication est possible entre deux entiers et qui effectue l'opération * @param i entier * @param j entier * @return boolean true si l'opération a été effectuée */ public boolean mul(int i,int j){ if(j>1){ r=i*j; ope[z]='*'; m1[z]=i; m2[z]=j; sauve(); return true; } return false; } /** * Méthode vérifiant que la division est possible entre deux entiers et qui effectue l'opération * @param i entier * @param j entier * @return boolean true si l'opération a été effectuée */ public boolean div(int i,int j){ if(j>1){ r=i/j; //if((r*j==i)&&(r!=j)){ ope[z]=':'; m1[z]=i; m2[z]=j; sauve(); return true;} // } return false; } public void calcul(int [] tab) { if(tab.length>1) { compteur++; if(tab.length==6)z=0; if(tab.length==5)z=1; if(tab.length==4)z=2; if(tab.length==3)z=3; if(tab.length==2)z=4; triDec(tab); System.out.println(""); for(int i=0; i