-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLista_03_Ex06.java
More file actions
29 lines (29 loc) · 828 Bytes
/
Copy pathLista_03_Ex06.java
File metadata and controls
29 lines (29 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Scanner;
class Lista_03_Ex06
{
public static void main(String [] args)
{
int n,contador,exp,sinal,x,den,a;
double s,fat;
Scanner teclado = new Scanner(System.in);
System.out.print("Digite a quantidade de termos da serie : ");
n = teclado.nextInt();
System.out.print("Digite o valor de x : ");
x = teclado.nextInt();
s = 0;
sinal = -1;
exp = 2;
den = 1;
for ( contador = 1; contador <= n; contador = contador + 1 )
{
fat = 1;
for ( a = 1; a <= den; a = a + 1 )
fat = fat * a;
s = s + sinal*Math.pow(x,exp) / fat;
sinal = -sinal;
exp = exp + 1;
den = den + 1;
}
System.out.println("Soma dos termos da série : " + s);
}
}