Advertisement
Guest User

Rangga faktorial

a guest
Nov 12th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import java.util.Scanner;
  2. class FactorialDemo{
  3. public static void main(String args[]){
  4. Scanner scanner = new Scanner(System.in);
  5. System.out.println("Angka :");
  6.  
  7. int num = scanner.nextInt();
  8.  
  9. int factorial = fact(num);
  10. System.out.println("Faktorial dari " +num+ ": "+factorial);
  11. }
  12. static int fact(int n)
  13. {
  14. int output;
  15. if(n==1){
  16. return 1;
  17. }
  18.  
  19. output = fact(n-1)* n;
  20. return output;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement