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

public class BPIH5E14
{
    public static double log(double x)
    {
	    // ln(x) = 1+y^2/3+y^4/5+y^6/7+...   y=(x-1)/(x+1)
	    //
	    double ln10=2.302585092994046;
        int m=0;
        int j=1;
        double z=x; 
        j=(int)z;         
        while(j>0) 
        {  	    
	    if(j>0) {x=z;m++;}
	    z=x/10;
	    j=(int)z;    
	    }
	    x=z;
	    	    	        
        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;
        ln+=m*ln10;
	    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 BPIH4E1
