Created
November 8, 2015 20:41
-
-
Save edinak1/5403b153357591aad78e to your computer and use it in GitHub Desktop.
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
| package test; | |
| public class Factorial { | |
| public static void main(String[] args) { | |
| System.out.println(factorial(-1)); | |
| System.out.println(factorial(0)); | |
| System.out.println(factorial(1)); | |
| System.out.println(factorial(2)); | |
| System.out.println(factorial(3)); | |
| System.out.println(factorial(5)); | |
| System.out.println(factorial(6)); | |
| } | |
| static long factorial(int i) | |
| { | |
| if(i<0 || i>20) | |
| { | |
| System.out.print("Give me another number"); | |
| return -1; | |
| } | |
| long rezalt=1; | |
| for(int k=2;k<=i;k++) | |
| { | |
| rezalt*=k; | |
| } | |
| return rezalt; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment