JAVA PROGRAM 2

itprofessionalsrocks.blogspot.com
java program 2:
To find out whether the roots of the quadratic equation are imaginary,real and equal and unequal .
 import java.util.*;
import java.lang.Math;
class roots
{
public static void main(String args[])
{

double d,d1,d2;
Scanner obj=new Scanner(System.in);
System.out.println("enter the valur of a");
int a=obj.nextInt();
System.out.println("enter the valur of b");
int b=obj.nextInt();
System.out.println("enter the valur of c");
int c=obj.nextInt();
 d=((b*b)-(4*a*c));
 if(d>0)
 { System.out.println("roots are real and unequal");
 System.out.println("value of d"+ d);
 d1=(-b+Math.sqrt(d))/2*a;
 d2=(-b-Math.sqrt(d))/2*a ;
 System.out.println(d1);
 }
 else if(d==0)
{ System.out.println("roots are real and equal");
 d1=(-b+Math.sqrt(d))/2*a;
 System.out.println("roots are"+d1);
 }
 else if(d<0)
 { System.out.println("roots are imaginary and unequal");
 System.out.println("value of d"+ d);
}
  }
  }

Comments

Popular posts from this blog

REFLECTION OF A TRIANGLE (COMPUTER GRAPHICS)