package Lecture3; import javax.swing.*; public class Iteration2 { public static void main(String[] args) { String entrada= JOptionPane.showInputDialog("Introduzca x (0-2)"); double x= Double.parseDouble(entrada); // Calcule 20 términos del // ln x= (x-1) - (x-1)^2/2 + (x-1)^3/3 - ... final double TOLERANCIA= 0.00001; double logx= 0.0; double x1= x-1; int i= 1; double term= 0.0; // Defínala fuera de do {} do { term= Math.pow(x1, i)/i; if (i % 2 == 0) // i par logx -= term; else logx += term; i++; } while (Math.abs(term) > TOLERANCIA); System.out.println("Ln x= " + logx); System.out.println("Encontrado en " + i + " iterationes"); System.exit(0); } }