class Quad{
public static void main(String args[])
{
int a,b,c;
double d,r1,r2;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
d=b*b-4*a*c;
if(d==0)
{
r1=-b+Math.sqrt(d)/(2*a);
System.out.println("Roots are real and equal:\nRoot="+r1);
}
else if(d>0)
{
r1=-b+Math.sqrt(d)/(2*a);
r2=-b-Math.sqrt(d)/(2*a);
System.out.println("Roots are real and unequal:\nRoot 1="+r1+"\nRoot 2="+r2);
}
else
System.out.println("Roots are imaginary.");
}
}
public static void main(String args[])
{
int a,b,c;
double d,r1,r2;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
d=b*b-4*a*c;
if(d==0)
{
r1=-b+Math.sqrt(d)/(2*a);
System.out.println("Roots are real and equal:\nRoot="+r1);
}
else if(d>0)
{
r1=-b+Math.sqrt(d)/(2*a);
r2=-b-Math.sqrt(d)/(2*a);
System.out.println("Roots are real and unequal:\nRoot 1="+r1+"\nRoot 2="+r2);
}
else
System.out.println("Roots are imaginary.");
}
}
No comments:
Post a Comment