public class Bisection {
private static void doBisection(double err) {
Scanner input = new Scanner(System.in);
System.out.println(“Enter left bound.”);
double x1 = input.nextDouble();
System.out.println(“Enter right bound”);
double xr = input.nextDouble();
double xm = 0;
while (Math.abs(xr – x1) > err) {
xm = (xr + x1) / 2;
if (func(x1) * func(xm) < 0) {
xr = xm;
} else {
x1 = xm;
}
}
System.out.println(xm);
}
private static double func(double x) {
return x – 5 * (1 – Math.exp(-x));
}
public static void main(String[] args) {
doBisection(1e-8);
}
}
I have used the code you have provided to proceed. The bisection method you provided will work only with increasing function, i.e. f(left bound) <= f(right bound). If you want anything more, please let me know through commens. I shall be glad to help you.