Skip to content

Instantly share code, notes, and snippets.

@edinak1
Created November 8, 2015 20:41
Show Gist options
  • Select an option

  • Save edinak1/5403b153357591aad78e to your computer and use it in GitHub Desktop.

Select an option

Save edinak1/5403b153357591aad78e to your computer and use it in GitHub Desktop.
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