Вы находитесь на странице: 1из 2

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/

package bisectionmethodsucgang;
import java.util.Scanner;
/**
*
* @author user2
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
double xl, xu, xr, fx;
System.out.print("\n This program will determine the roots of the equation
f(x)=x^2+7x+12");
System.out.print("\n Enter the lower limit: ");
xl=input.nextDouble();
System.out.print("\n Enter the upper limit: ");
xu=input.nextDouble();

System.out.print("\n counter\t
int c;
c=1;

xl\t

xu\t

xr\t

fx\t");

do
{
xr=(xu+xl)/2;
fx= Math.pow(xr,2)+(7*xr)+12;
System.out.printf("\n

%d\t %11.4f\t %12.4f\t %13.4f\t %14.4f" , +c,+xl,+xu,+xr,

+fx);
if (fx>0)
{
xu=xr;
}
else
{
xl=xr;
}
c++;
}

while((Math.abs(fx))>=0.00001);
System.out.printf("\n The root of the equation is: %5.4f\n", +xr);
System.out.print("\n ");
System.out.print("\n ");
}

Вам также может понравиться