Public static boolean recherche(int tableau [],int x ,int rang ) { If( rang>=tableau.length) return false; Else if(tableau[rang]==x) return true; Else return recherche(?,rang+1,x); } Dans le main on déclare son tableau ? Public static void main (string args []){ Int tableau[]={2.1.4}; System.out.println(recherche(?,0,x)); }
public static boolean recherche(int tableau[], int x, int rang) { if (rang >= tableau.length) return false; else if (tableau[rang] == x) return true; else return recherche(tableau, x, rang + 1); } public static void main(String args[]) { int tableau[] = { 2, 1, 4 }; int x = 3; // valeur à chercher System.out.println(recherche(tableau, x, 0)); }
EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ICI Merci d'y penser dans tes prochains messages. |
public static void inte(int []TableauA,int a,int Tableau [] B,int b,ArrayList<Integer> TableauC,int c){ ArrayList<Integer> TableauC = new ArrayList<Integer> (); if(a>=TableauA.length || b>=TableauB.length) return inte; else if(TableauA[a]==TableauB[b]){ c++; TableauC.add(TableauA[a]); ;} return inte(TableauA,a+1,TableauB,b+1,TableauC,c); } public static void main(String[] args){ //déclaration tableau + system.out.println(lesparamètres) }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic static ArrayList<Integer> inte(int TableauA[], int a, int TableauB[], int b, int c) { ArrayList<Integer> TableauC = new ArrayList<Integer>(); if (a >= TableauA.length || b >= TableauB.length) return TableauC; else if (TableauA[a] == TableauB[b]) { c++; TableauC.add(TableauA[a]); } return inte(TableauA, a + 1, TableauB, b + 1, c); } public static void main(String args[]) { int TableauA[] = { 1, 2, 3 }; int TableauB[] = { 1, 2, 3 }; int a = 1; int b = 1; int c = 0; ArrayList<Integer> TableauC = inte(TableauA, a, TableauB, b, c); for (int i = 0; i < TableauC.size(); i++) { System.out.println(TableauC.get(i)); } }
public static List<Integer> inte(int[] TableauA, int[] TableauB) { List<Integer> TableauC = new ArrayList<Integer>(); inte(TableauA, 0, TableauB, 0, TableauC); return TableauC; } private static void inte(int[] TableauA, int a, int[] TableauB, int b, List<Integer> TableauC) { if (a >= TableauA.length || b >= TableauB.length) return; if (TableauA[a] == TableauB[b]) TableauC.add(TableauA[a]); inte(TableauA, a + 1, TableauB, b + 1, TableauC); } public static void main(String args[]) { int[] TableauA = { 1, 2, 3 }; int[] TableauB = { 1, 2, 3 }; System.out.println(inte(TableauA, TableauB)); }