Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class FactorialDemo{
- public static void main(String args[]){
- Scanner scanner = new Scanner(System.in);
- System.out.println("Angka :");
- int num = scanner.nextInt();
- int factorial = fact(num);
- System.out.println("Faktorial dari " +num+ ": "+factorial);
- }
- static int fact(int n)
- {
- int output;
- if(n==1){
- return 1;
- }
- output = fact(n-1)* n;
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement