Last active
August 22, 2017 16:08
-
-
Save jimywork/7fbf31a18c2c229d8a19ca571285ee23 to your computer and use it in GitHub Desktop.
Exercício de Repeticao Java
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
/* Faça um programa que leia um valor N inteiro e positivo, calcule e mostre o valor de E, conforme a fórmula a seguir: | |
E = 1 + 1/1! + ½! + 1/3! + ... + 1/N! */ | |
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
int numero; | |
double r = 0, fatorial; | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Digite um numero:"); | |
numero = scanner.nextInt(); | |
for(int i = 1; i <= numero; i++) { | |
fatorial = 1; | |
for(int j = 1; j <= i; j++) { | |
fatorial = fatorial * j; | |
} | |
r = r + 1 / fatorial; | |
} | |
System.out.print(r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment