Dificuldade com a logica de programação
Bem, estou resolvendo um problema " faça um programa que leia um numero "n" ( n > 0 ) e calcule o valor de R pela formula : 15 - 15/3 + 15/5 - 15 / 7 + ..... + 15/2*n+1", estou sem saber qual função utilizar para prosseguir com o código.... sou bem novato na area então quem poder dar uma luz eu agradeço....
Código até agora :
Código até agora :
import java.util.Scanner;
public class projeto2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n;
int d;
int r;
int a;
System.out.println("Informe o valor de N");
Scanner s = new Scanner(System.in);
n = s.nextInt();
if (n <= 0){
System.out.println("valor de N Invalido");
}
else {
int f[] = new int[n];
r = s.nextInt();
d = s.nextInt();
}
}
}
Gabriel Augusto
Curtidas 0
Respostas
Gabriel Augusto
15/05/2018
resolução do problema :
package questão2;
import java.util.Scanner;
public class teste {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int num;
num = 0;
int i;
double soma = 15;
// perguntando os dados //
System.out.println("Informe o valor de N");
Scanner s = new Scanner(System.in);
num = s.nextInt();
// se o n é maior que 0 ou não //
if (num > 0) {
do {
if (num > 0) {
System.out.printf("15");
for (i = 1 ; i <= num; i++) {
if (i%2 ==0) {
System.out.printf("-15/%d", (2*(+i))+ 1);
soma -= 15/ ((2*i) + 1);
}
else
{
System.out.printf("+15/%d", (2*(+i)) + 1);
soma += 15/((2*i)+1);
}
}
System.out.println("resultado é " +soma);
}
num = num - num ;
}while(num > 0);
}
// quando n for menor ou igual a zero//
else {
System.out.println("valor invalido");
}
}
}
GOSTEI 0
Anna Shetty
15/05/2018
This article is useful for know about the root security of the containers. I got the knowledge of working of containers with the root behavior with the kernel.
<a href="http://coolmath-games.io/game/run-3">run 3 cool math</a>
<a href="http://coolmath-games.io/game/run-3">run 3 cool math</a>
GOSTEI 0
Funnyjokes
15/05/2018
The information you share is very useful. It is closely related to my work and has helped me grow. Thank you!
http://tellfunnyjokes.com
http://tellfunnyjokes.com
GOSTEI 0
Funnyjokes
15/05/2018
The information you share is very useful. It is closely related to my work and has helped me grow. Thank you!
[URL=http://tellfunnyjokes.com]funny jokes[/URL]
[URL=http://tellfunnyjokes.com]funny jokes[/URL]
GOSTEI 0
Leo Andrade
15/05/2018
Nao saquei essa formula da variavel r ai nao.<br />
divisor sempre aumenta +1? sempre aumenta r?
divisor sempre aumenta +1? sempre aumenta r?
GOSTEI 0