Skip to content

Instantly share code, notes, and snippets.

@rich-97
Last active March 26, 2017 00:36
Show Gist options
  • Save rich-97/ef76c36fe0e274dfc9edd7461cbfc2bb to your computer and use it in GitHub Desktop.
Save rich-97/ef76c36fe0e274dfc9edd7461cbfc2bb to your computer and use it in GitHub Desktop.
Java factorial
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