solve quadratic equation in java

import java.io.*;
class Root
{
public static void main(String args[])throws IOException
{
 int a,b,c;
 double d,x,y;
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter the value of a,b,c");
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
d=b*b-4*a*c;
if(d>=0)
{
if(d==0)
{
x=-b/(2*a);
y=-b/(2*a);
System.out.println("roots are real and equal,so the number is perfect square");
}
else

{
System.out.println("roots are real and distinct");
}
}
else
{
System.out.println("roots are imaginary");
}
}
}
class square
{
public void root1(int x,int y,int z )
{
a=x;
b=y;
c=z;
r1=((-b)+(Math.sqrt(d)))/(2*a);
r2=((-b)-(Math.sqrt(d)))/(2*a);
System.out.println("first root is"+r1);
System.out.println("second root is"+r2);
}

Post a Comment