import javax.swing.*; // program poweres class Scanner

public class logarithmatesti
{
    public static double log(double x) throws minuslogarithmException
    {
        // ln(x) = 1+y^2/3+y^4/5+y^6/7+...   y=(x-1)/(x+1)
        if(x<0) throw new minuslogarithmException();	        
        double power=1;
        double ln=1;
        double y=(x-1)/(x+1);
        double n=1;
        do
        {
        power*=y*y;
        ln+=power /(2.0*n+1.0);     
        n++;
        } while(n<=100000);
        ln*=2*y;
	    return ln;
     } 
	// main method begins execution of Java application
     public static void main( String args[] )
     {            
        String s; 
        double x=Double.parseDouble(JOptionPane.showInputDialog("Enter a real number: ")); // read number
        s="log("+x+") = "+log(x)+"   "+"Math library ="+Math.log(x);
        JOptionPane.showMessageDialog(null,s,"natural logarithm calculation",JOptionPane.PLAIN_MESSAGE);
     } // end method main
} // end class
