Created
June 4, 2018 21:58
-
-
Save lucasheriques/11df3ea8bd05d35d346125ed3670dcf0 to your computer and use it in GitHub Desktop.
This file contains 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
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