Advertisement
Alrarapie

Faktorial

Nov 18th, 2021
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Faktorial {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = scanner.nextInt();
  7.         System.out.println(faktorial(n));
  8.     }
  9.     //Method Faktorial
  10.     public static int faktorial(int a){
  11.         if (a==1) {
  12.             System.out.print(1 + " = ");
  13.             return 1;
  14.         }
  15.         System.out.print(a+" x ");
  16.         return a*faktorial(a-1);
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement