Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package a;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class A {
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. double x = in.nextDouble();
  10. double y = in.nextDouble();
  11. int cont = 0;
  12. if(x < 1 && y < 1) {
  13. double soma = 0;
  14. int expx = 1;
  15. int expy = 1;
  16. boolean par = true;
  17. double termoAtual = x*y;
  18. soma += termoAtual;
  19. while(termoAtual > 0.001) {
  20. expx++;
  21. expy += 2;
  22. double termox = 1;
  23. double termoy = 1;
  24. double termoCima;
  25. double termoo = x+y;
  26. double termoBaixo = 1;
  27. for(int i = 0; i < expy; i++) {
  28. if(i < expx) {
  29. termox *= x;
  30. }
  31. termoy *= y;
  32. }
  33. termoCima = termox*termoy;
  34. for(int i = 0; i < expy*expx; i++) {
  35. termoBaixo *= termoo;
  36. }
  37. termoAtual = termoCima/termoBaixo;
  38. if(par) {
  39. soma += termoAtual;
  40. par = false;
  41. }else {
  42. soma -= termoAtual;
  43. par = true;
  44. }
  45. cont++;
  46. System.out.println(cont);
  47. }
  48. System.out.println(soma);
  49. }else {
  50. System.out.println("Números inválidos");
  51. }
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement