recursion what is code example
Example 1: recursion
/*Java*/
static void recursion(){ recursion(0); }
static void recursion(int x){
System.out.println("eheh " + x);
if(x != 666) recursion(x+1);
}
Example 2: Recursion
/**
* Return all subsequences of word (as defined above) separated by commas,
* with partialSubsequence prepended to each one.
*/
private static String subsequencesAfter(String partialSubsequence, String word) {
if (word.isEmpty()) {
// base case
return partialSubsequence;
} else {
// recursive step
return subsequencesAfter(partialSubsequence, word.substring(1))
+ ","
+ subsequencesAfter(partialSubsequence + word.charAt(0), word.substring(1));
}
}