Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Date;
- public class Factorial {
- private int computing = 0;
- public int factorial(int n) {
- if (n == 1){
- System.out.println(n + " = 1 [ " + new Date().getTime() + " ]");
- return 1;
- }
- else{
- computing = n * factorial(n - 1);
- System.out.println(n + " * factorial(" + n + " - 1) = " + computing + " [ " + new Date().getTime() + " ]");
- return computing;
- }
- }
- public static void main(String[] args) {
- Factorial newFactorial = new Factorial();
- int answer = newFactorial.factorial(6);
- System.out.println("\nThe factorial of 6 is " + answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement