Advertisement
ledkaa

factorial

May 26th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner=new Scanner(System.in);
  6. int n= scanner.nextInt();
  7. scanner.nextLine();
  8. System.out.println(factorial(n));
  9. }
  10.  
  11. private static int factorial(int n) {
  12. if (n == 1) {
  13. return 1;
  14. }
  15. return n * factorial(n - 1);
  16. }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement