Skip to content
Permalink
Browse files

Merge pull request #932 from TheRenegadeCoder/java-fact

Added Factorial in Java
  • Loading branch information...
jrg94 committed Dec 31, 2018
2 parents b474a91 + 6bcf0df commit 6d412d0c8887c8529c37ba7d0e0ba63f9ba89bed
Showing with 32 additions and 2 deletions.
  1. +29 −0 archive/j/java/Factorial.java
  2. +3 −2 archive/j/java/README.md
@@ -0,0 +1,29 @@
public class Factorial
{
public static long fact(long n)
{
if (n <= 0)
return 1;
return n * fact(n - 1);
}

public static void main(String[] args)
{
try
{
long n = Long.parseLong(args[0]);
if (n > 59)
{
System.out.println(String.format("%1$s! is out of the reasonable bounds for calculation.", n));
System.exit(1);
}
long result = fact(n);
System.out.println(result);
}
catch (NumberFormatException e)
{
System.out.println("Usage: please input a number");
System.exit(1);
}
}
}
@@ -6,10 +6,11 @@ Welcome to Sample Programs in Java!

- [Baklava in Java](https://github.com/TheRenegadeCoder/sample-programs/issues/934)
- [Hello World in Java](https://therenegadecoder.com/code/hello-world-in-java/)
- [Reverse a String in Java](https://therenegadecoder.com/code/java/reverse-a-string-in-java/)
- [Factorial in Java](https://github.com/TheRenegadeCoder/sample-programs/issues/931)
- [Fibonacci in Java](https://github.com/TheRenegadeCoder/sample-programs/issues/483)
- [Fizz Buzz in Java](https://github.com/TheRenegadeCoder/sample-programs/issues/400)
- [Game of Life in Java](https://github.com/jrg94/sample-programs/issues/108)
- [Fibonacci Sequence](https://github.com/TheRenegadeCoder/sample-programs/issues/483)
- [Reverse a String in Java](https://therenegadecoder.com/code/java/reverse-a-string-in-java/)

## Fun Facts

0 comments on commit 6d412d0

Please sign in to comment.
You can’t perform that action at this time.