Skip to content

Instantly share code, notes, and snippets.

@lucasheriques
Created June 4, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasheriques/11df3ea8bd05d35d346125ed3670dcf0 to your computer and use it in GitHub Desktop.
Save lucasheriques/11df3ea8bd05d35d346125ed3670dcf0 to your computer and use it in GitHub Desktop.
public class Fatorial {
public static int fatorial(int x) {
if (x == 0)
return 1;
int total = x;
for (int i = x - 1; i > 0; i--) {
total *= i;
}
return total;
}
public static void main(String[] args) {
System.out.println("4! = " + fatorial(4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment