# Program to implement a Quadratic equation in Java

- Link: https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/
- Published: 2018-11-03T21:46:58+05:30
- Author: Ashishkumar Vishwakarma

In this program, you will learn to find all roots of a quadratic equation in Java.

Also, you can use the Java [compiler](https://www.onlinegdb.com/online_java_compiler)
to compile a program.

![Program to implement a Quadratic equation in Java](https://technotaught.com/wp-
content/uploads/2020/11/Quadratic-equation.png)

## Program to implement all Roots of a Quadratic equation in java

The standard form of equation is:

    ```wp-block-preformatted
    ax2 + bx + c = 0, where
    a, b and c are real numbers and
    a ≠ 0
    ```

The term `b^(2)-4ac` is known as the determinant of an equation. The determinant
tells the nature of the roots.

 * If the determinant is greater than 0, the roots are real and different.
 * And determinant is equal to 0, the roots are real and equal.
 * If the determinant is less than 0, the roots are complex and different.

##### SOURCE CODE.

    ```javascript
    import java.util.*;
    class quadratic3
    {
    	public static void main(String args[])
    	{
    		int e,a,b,c;
    		double l,x,y;
    		Scanner s= new Scanner(System.in);
    		System.out.println("Enter value a,b,c:");
    		a=s.nextInt();
    		b=s.nextInt();
    		c=s.nextInt();

    		e=b*b-4*a*c;
    		if(e<0)
    		{
    			System.out.println("NOT REAL");
    		}
    			else if(e == 0) 
    		{
                     x = -b / (2.0 * a);
                    System.out.println("The root is " + x);
    		}
    		else 
    		{
    			l=Math.sqrt(e);
    			x= (-b+l)/(2*a);
    			y= (-b-l)/(2*a);
    			System.out.println("equation= "+x+" & "+y);
    		}
    	}// END OF MAIN
    }//END OF CLASS	
    ```

#### OUTPUT.

> C:\A>javac quadratic3.java
> C:\A>java quadratic3Enter value a,b,c:144The root is-
> 2.0

#### OR

> C:\A>javac quadratic3.java
> C:\A>java quadratic3Enter value a,b,c:152equation= -
> 0.4384471871911697 & -4.561552812808831

Also view: – [Command-Line program find the Largest number](https://technotaught.com/command-line-program-find-the-largest-number/)

### Share this:

 * [  X ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=twitter)
 * [  Facebook ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=facebook)
 * [More](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/#)

 * [  WhatsApp ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=jetpack-whatsapp)
 * [  LinkedIn ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=linkedin)
 * [  Email ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?subject=%5BShared%20Post%5D%20Program%20to%20implement%20a%20Quadratic%20equation%20in%20Java&body=https%3A%2F%2Ftechnotaught.com%2Fprogram-to-implement-a-quadratic-equation-in-java%2F&share=email)
 * [  Reddit ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=reddit)
 * [  Tumblr ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=tumblr)
 * [  Pinterest ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=pinterest)
 * [  Telegram ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/?share=telegram)
 * [  Print ](https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/#print?share=print)

## Comments

### By: Cecil Porter

- Link: https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/#comment-126
- Published: 2020-04-22T02:24:20+05:30

Thanks for the info 🙂

### By: Add URL

- Link: https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/#comment-122
- Published: 2020-04-19T01:20:22+05:30

I think this is among the most vital info for me. And i’m glad reading your article.
But should remark on few general things, The site style is great, the articles is
really nice : D. Good job, cheers

### By: Jonathon Earl

- Link: https://technotaught.com/program-to-implement-a-quadratic-equation-in-java/#comment-116
- Published: 2020-04-16T22:40:05+05:30

Hey very nice web site!! Man .. Beautiful .. Superb .. I will bookmark your blog
and take the feeds additionally…I am happy to search out so many helpful information
here within the publish, we want work out extra strategies on this regard, thanks
for sharing.
