Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Factorial
- {
- public static String fact(int n)
- {
- if(n == 1)
- {
- return "1";
- }
- return n + " * " + (fact(n-1));
- }
- public static void main(String[] args)
- {
- // prints "5 * 4 * 3 * 2 * 1"
- System.out.println(fact(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement