Skip to content

Instantly share code, notes, and snippets.

@mkyy
Created August 30, 2018 21:22
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 mkyy/dc88c14c08defec306d41e7cd8497fb0 to your computer and use it in GitHub Desktop.
Save mkyy/dc88c14c08defec306d41e7cd8497fb0 to your computer and use it in GitHub Desktop.
fatorial whit recursivity function
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