Advertisement
MnMWizard

Factorial Assignment

Dec 22nd, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. // Mason Marnell - Factorial
  2. import static java.lang.System.in;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class SumOfDigits {
  7.  
  8. public static int sumDigits(int num){
  9. if(num <= 1) return num;
  10. return sumDigits(num-1) * num;
  11.  
  12. }
  13.  
  14.  
  15. public static void main(String[] args) {
  16. Scanner keyb = new Scanner(in);
  17. System.out.println("Enter a factorial (without the !)");
  18. int nm = keyb.nextInt();
  19. System.out.println(sumDigits(nm));
  20.  
  21. }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement