Roots of a Quadratic Equation 

Aim:
To write a java program that prints all real solutions to quadratic equation ax2+bx+c= 0.

Description: 
Write main method in a class named Quadratic. a, b and c are variables of type double for which we will assign some values. Variable d is used to store discriminant value (i.e., b*b – 4*a*c). r1, r2 are two double variables used to store two roots when discriminant value that is d is greater than zero. When d is greater than zero, the two roots are real. When d is equal to zero, the two roots are equal. When d is less than zero, the two roots are imaginary.

Program:
class Quadratic
{ public static void main(String args[])
{
double a=5,b=10,c=2,r1,r2,d;
d=(b*b)-(4*a*c);
if(d==0)
{ System.out.println("Roots are real and equal");
System.out.println("The roots are : " + (-b/(2*a) ) );
}
else if(d<0)
System.out.println("The roots are imaginary");
else if(d>0)
{ r1=-b+(Math.sqrt(d))/(2*a);
r2=-b-(Math.sqrt(d))/(2*a);
System.out.println("root1=" + r1);
System.out.println("root2=" + r2);
}
}
}