Created
August 30, 2018 21:22
-
-
Save mkyy/dc88c14c08defec306d41e7cd8497fb0 to your computer and use it in GitHub Desktop.
fatorial whit recursivity function
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
import java.util.Scanner; | |
public class fatorial { | |
static int Fatorial(int N) { | |
if (N>1) { //enquanto nao for o caso base retorna na funçâo | |
return N * Fatorial(N-1); | |
} else // aqui termina a recursividade | |
return 1; | |
} | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
System.out.println("entre com o numero"); | |
int N = scn.nextInt(); | |
int res = Fatorial(N); | |
System.out.println(res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment