home
Guest Signup/Login to unlock all features

Menu

Views: 1063

Replies: 2

Share this post
facebook twitter gplus

avatar

Member

rusell

Java Program To solve Quadratic Equation

Feb 18 2017 at 09:25am

public class QuadraticEquationSolver
{
public static void main(String[] args)
{
/*Suppose our Quadratic Equation to be
solved
* is 2x2 + 6x + 4 = 0 .
* (Assuming that both roots are real
valued)
*
* General form of a Quadratic Equation
is
* ax2 + bx + c = 0 where 'a' is not
equal to 0
*
* Hence a = 2, b = 6 and c = 4.
*/
int a =2;
int b =6;
int c =4;
//Finding out the roots
double temp1 = Math.sqrt(b * b -4* a *
c);
double root1 = (-b + temp1) / (2*a) ;
double root2 = (-b - temp1) / (2*a) ;
System.out.println( "The roots of the
Quadratic Equation \"2x2 + 6x + 4 =
0\" are "+root1+" and "+root2);
}
}



avatar

ADMIN

eaweb

Re: Java Program To solve Quadratic Equation

Feb 18 2017 at 10:51am

* is 2x2 + 6x + 4 = 0

Though this is only a comment it took me some time to realise that 2x2 is actually 2x raised to the power of 2 we usually represent this as 2x^2 when typing sha. It's generally easier to understand.

Overall nice code. Very useful for academic work.


quote ()
avatar

Member

rusell

Re: Java Program To solve Quadratic Equation

Feb 18 2017 at 09:54pm

yeah


quote ()

Quick reply


+ files BBCode

Sponsored