Last active
March 26, 2017 00:36
-
-
Save rich-97/ef76c36fe0e274dfc9edd7461cbfc2bb to your computer and use it in GitHub Desktop.
Java factorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class Factorial { | |
| public static int fact (int val) { | |
| if (val == 0) | |
| return 1; | |
| return val * fact(val - 1); | |
| } | |
| public static void main (String args[]) { | |
| Scanner input = new Scanner(System.in); | |
| int val; | |
| System.out.print("Enter a number: "); | |
| val = input.nextInt(); | |
| System.out.print(fact(val)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment