<pre>import java.util.Arrays; public class HavreiKnesetMain { public static int isSuitable(HavreiKneset [] arr, String miflaga, boolean migdar) { int count=0; int index=0; if(index>=arr.length) { return 1; } else { index++; if(arr[index].getNameOfMiflaga().equals(miflaga) && arr[index].isGender()==migdar) { count++; } return count + isSuitable(arr,miflaga,migdar); } } public static void main(String[] args) { HavreiKneset [] arr = new HavreiKneset[4]; HavreiKneset h1 = new HavreiKneset("Nissim", "meretz",true, true); HavreiKneset h2 = new HavreiKneset("Rina", "Reshima Meshutefet",false, false); HavreiKneset h3 = new HavreiKneset("Dorit", "kahol lavan",true, false); HavreiKneset h4 = new HavreiKneset("Ziv", "meretz",true, true); arr[0]=h1; arr[1]=h2; arr[2]=h3; arr[3]=h4; System.out.println(Arrays.toString(arr)); System.out.println(isSuitable(arr,"meretz",true)); } }
int index=0; if(index>=arr.length) { return 1; }
index
int recursiveMethod(int index, arr[] things) { if (index >= things.length) { return 1; } else { int result = recursiveMethod(index + 1, things); } } // then you start with public static void main(String[] args) { int result = recursiveMethod(0, myArray); }
local variables
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)