Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Examples/Recursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class HelloWorld{

public static void main(String[] args){

static int fact(int n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the return type be long . Otherwise, would it be able to return fatorial to numbers greater than 100?

{
if (n == 1)

// base condition
return 1;
else
return n*fact(n-1);
}
public static void main(String[] args) {
int result = fact(10);

System.out.println("10! = " + result);
}
}
}