// Java program for the above approach
import java.util.*;
import java.lang.*;
class GFG{
static final double eps = 1e-6;
// Given function
static double func(double a, double b,
double c, double x)
{
return a * x * x + b * x + c;
}
// Function to find the root of the
// given non-decreasing Function
static double findRoot(double a, double b,
double c, double low,
double high)
{
double x = -1;
// To get the minimum possible
// answer for the root
while (Math.abs(high - low) > eps)
{
// Find mid
x = (low + high) / 2;
// Search in [low, x]
if (func(a, b, c, low) *
func(a, b, c, x) <= 0)
{
high = x;
}
// Search in [x, high]
else
{
low = x;
}
}
// Return the required answer
return x;
}
// Function to find the roots of the
// given equation within range [a, b]
static void solve(double a, double b, double c,
double A, double B)
{
// If root doesn't exists
if (func(a, b, c, A) * func(a, b, c, B) > 0)
{
System.out.println("No solution");
}
// Else find the root upto 4
// decimal places
else
{
System.out.format("%.4f", findRoot(
a, b, c, A, B));
}
}
// Driver Code
public static void main (String[] args)
{
// Given range
double a = 2, b = -3, c = -2,
A = 0, B = 3;
// Function call
solve(a, b, c, A, B);
}
}
// This code is contributed by offbeat