import java.io.*;
import javax.swing.*;
import javax.tools.*;
import java.util.*;
import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.Locale;
import java.text.*;
import java.util.*;
import javax.swing.table.*;

class ce2B 
{ 	 public double r;	
	 public ce2B(double x1) 
	 {     
        f2D ff=new f2D();
        r= stephensen(ff,x1);
     }

public static double stephensen(f_x f,double x0)
{
//Stephensen root finding method
double es,ea;
int maxit=100,iter=0;
es=0.000001;
ea=1.1*es;
double x,x1,x2;
x=0;
while(iter<maxit && ea>es)
{
x1=f.func(x0);
x2=f.func(x1);
x=x0-(x1-x0)*(x1-x0)/(x2-2*x1+x0);
ea=Math.abs(x-x0)*100.0;
x0=x;
iter++;
}
if(iter>=maxit) JOptionPane.showMessageDialog(null,"Maximum number of iteration is exceeded \n"+
   " result might not be valid","MAKSİMUM NUMBER OF ITERATION WARNING",JOptionPane.WARNING_MESSAGE); 
return x;
}
}
