Accept integer values for a, b and c which are coefficients of quadratic equation. Find the solution of quadratic equation.

in this tutorial we are learn about quadratic equation.
so in algebra the quadratic equation is any equation that can be rearrange in standard form

quadratic equation


where x represent unknown number, and a b c represent a known number where a ≠ 0 . if a=0 than the equation is liner not a 
quadratic, as their is no ax^2 term . a , b and c are 
coefficient of the equation and may be distinguish 
by calling them . 
 
code:

import java.util.Scanner;

public class QuadraticEquation

{

public static void main(String []args)

{

int a,b,c;

double root1,root2,d;

Scanner s=new Scanner(System.in);

System.out.println("Given quadratic equation:ax^2+bx+c");

System.out.print("Enter a:");

a=s.nextInt();

System.out.print("Enter b:");

b=s.nextInt();

System.out.print("Enter c:");

c=s.nextInt();

System.out.println("Given quadratic equation:"+a+"x^2+"+b+"x+"+c);

d=b*b-4*a*c;

if(d>0)

{

System.out.println("Roots are real and unequal");

root1=(-b+Math.sqrt(d))/(2*a);

root2=(-b-Math.sqrt(d))/(2*a);

System.out.println("First root is:"+root1);

System.out.println("second root is:"+root2);

}

else if(d==0)

{

System.out.println("Roots are real and equal");

root1=(-b+Math.sqrt(d))/(2*a);

System.out.println("Root:"+root1);

}

else

{

System.out.println("Roots are imaginary");

}

}

}

Output:

Accept integer values for a, b and c which are coefficients of quadratic equation. Find the solution of quadratic equation.







Post a Comment

0 Comments