Created
September 2, 2014 01:16
-
-
Save gusthavosouza/ee7c5e75c0fab3b07607 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
import java.util.Scanner; | |
public class Fatorial { | |
static int num1, num2, resultado = 0; | |
static int calculaFatorial(int num1) { | |
if (num1 == 0) { | |
return 1; | |
} | |
return num1 *= calculaFatorial(num1 - 1); | |
} | |
static void lerNumeros() { | |
Scanner teclado = new Scanner(System.in); | |
System.out | |
.println("Digite o primeiro Nº Inteiro para calcular o fatorial!"); | |
num1 = teclado.nextInt(); | |
System.out | |
.println("Digite o Segundo Nº Inteiro para calcular o fatorial!"); | |
num2 = teclado.nextInt(); | |
} | |
public static void main(String[] args) { | |
lerNumeros(); | |
resultado = calculaFatorial(num1); | |
resultado += calculaFatorial(num2); | |
System.out.println("O resultado de " + num1 + "! +" + num2 + "! = " | |
+ "" + resultado); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment