how to write recursive functions java code example
Example: recursion in java
class scratch{
public static long factorial(int n){
if ( n == 1 ){
return 1;
}
else{
return n * factorial( n - 1 );
}
}
public static void main(String[] args) {
System.out.println( factorial(5) );
//Print 120 (5!) to the console
}
}