Quadratic Equation - Coder's point

Monday, March 25, 2019

Quadratic Equation

 import java.util.*;   
 class quadratic   
 {   
   public static void main(String args[])   
   {   
     int a,b,c,x;   
     System.out.println("Enter the value of a,b,c");   
     Scanner in = new Scanner(System.in) ;  
     a=in.nextInt();   
     b=in.nextInt();   
     c=in.nextInt();   
     int d=(b*b-(4*a*c));   
     double temp=Math.sqrt(d);   
     double root1=(-b+temp)/(2*a);   
     double root2=(-b-temp)/(2*a);   
     System.out.println("Roots of quadratic equation = "+root1+" ," + root2);   
   }   
 }   
OUTPUT :
Enter the value of a,b,c
1
2
1
Roots of quadratic equation = -1.0 ,-1.0

No comments:

Post a Comment