Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a;
- import java.util.Scanner;
- public class A {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- double x = in.nextDouble();
- double y = in.nextDouble();
- int cont = 0;
- if(x < 1 && y < 1) {
- double soma = 0;
- int expx = 1;
- int expy = 1;
- boolean par = true;
- double termoAtual = x*y;
- soma += termoAtual;
- while(termoAtual > 0.001) {
- expx++;
- expy += 2;
- double termox = 1;
- double termoy = 1;
- double termoCima;
- double termoo = x+y;
- double termoBaixo = 1;
- for(int i = 0; i < expy; i++) {
- if(i < expx) {
- termox *= x;
- }
- termoy *= y;
- }
- termoCima = termox*termoy;
- for(int i = 0; i < expy*expx; i++) {
- termoBaixo *= termoo;
- }
- termoAtual = termoCima/termoBaixo;
- if(par) {
- soma += termoAtual;
- par = false;
- }else {
- soma -= termoAtual;
- par = true;
- }
- cont++;
- System.out.println(cont);
- }
- System.out.println(soma);
- }else {
- System.out.println("Números inválidos");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement