techhipbettruvabetnorabahisbahis forumutaraftarium24eduseduedusedueduedusedueduseduedu Java Program: Calculate Roots of Quadratic Equation | Java Programs
Latest :

Java Program: Calculate Roots of Quadratic Equation | Java Programs

Java program to calculate roots of the quadratic equation – The following program has been written in 2 simple ways.

A quadratic equation is of the form ax2+bx+c=0 where a,b,c are known numbers while x is the unknown. Our problem statement is to write a code to find the roots of this equation.

Roots of the equation are the values which when substituted in place of x satisfies the condition. For a quadratic expression of this form there are 2 roots.

For this, we required 3 inputs-a, b, c which can be an integer or decimal so, we make use of the double data type. We read these input values at runtime with the help of Scanner class which helps us read any primitive datatype value at runtime. But before that, we need to create an object to instantiate the Scanner class and make use of its methods. These can be done as given below:

Scanner sc = new Scanner(System.in);

a= sc.nextFloat();

b= sc.nextFloat();

c= sc.nextFloat();

After collecting our inputs, we make a method call for a method (names FindRoots). The inputs (a,b,c) are passed as arguments for this method. In this method, we first find the determinant or det. Det can be found using the formula:

det=b * b – 4 * a * c;

Based on this value of det, there are three possible cases.

  1. When det is positive or if det>0 then, the two roots are real and unique. These root values can be found with formula-> root1 = (-b + Math.sqrt(det)) / (2 * a) , root2 = (-b – Math.sqrt(det)) / (2 * a). We make use of the sqrt method of Math package to find the squareroot.
  2. When the value of det is 0 or if d==0 then, the two roots are real and equal. Th roots can be found using the formula -> root1 = root2 = -b / (2 * a).
  3. When the value of det is negative or if det<0 then, the roots are imaginary. One of the root will have realpart+imaginarpart while another will have realpart-imaginarypart. The real and imaginary part can be found using->    imaginaryPart = Math.sqrt(-det) / (2 * a)      whereas the realPart = -b / (2 *a)

This way we can find the roots of any given quadratic equations for the known value of a, b, c. These roots can further be displayed in our console screen.

Output:

techhipbettruvabetnorabahisbahis forumutaraftarium24edueduedueduseduedusedusedusedusedu
x

Check Also

Java Program To Reverse An Array | Programs

Java program to reverse an array – We will discuss the various methods to reverse ...

grandpashabetExtrabethacklink satın alcasibomakcebet uyeliksupertotobet1xbet girişmelbet girişbetwinnerpinup uyelikbtcbahis girişmostbet girişbetwinner girişxslotskyloft uyelikmegapari uyelikistanbulkart başvurugrandpashabetgrandpashabetmariobett.mebetandreasenbetcasivalmisbahismyhitbetonbahistipobetbahsinevavepasgolgrandpashabetmarsbahispusulabetcasibomcasibom girişcasibom güncel girişcasibomcasibom girişdeneme bonusu veren sitelercasibom 850https://mobilebarhawaii.com/ballettea tropazjokerbet güncel girişmatadorbetbets10betturkeycasibomxslotjojobetcasibom girişjojobet girişmaldives casinohacklinkgrandpashabetbetmatik girişmelbetmostbetmegapari üyelikistanbul escortmatadorbetjojobetbets10 girişJojobettakipci alpinco girisstake girişmarsbahis telegramtrendbetMarsbahismarsbahisbetgitbetwoonCasibomstake giriş twitteronwinonwin girişjokerbet güncel girişpusulabet güncel girişmaldives casinocasino maldivesmaldives betmaldives online casinomaldives online betjojobet girişonwinFethiye escortMersin escortMersin escortjojobet güncel girişselcuksportshdCasibom Günceltürk pornosekabetjojobetatakoy escortatakoy escortsisli escortbetgarantipadişahbet girişbets10 girişjojobetgalatabahisbetparkCasibombets10 girişprimebahisliste paris sportifjeux casino gratuit avec bonusSimsinos Casinojojobet girişCashimashi AvisWunderWinsparier sur les cornersGamdomCasibomMarsbahis güncel girişcasibom girişbetmarino yeni girişpinbahisemiratesbettrbetjojobetcasibomhızlı giriş adresicratosroyalbetvaycasinobets10 girişbets10casinokaliprensbetimajbetmatbetsekabetonwinsahabetmarsbahisholiganbetcasinomaximobilbahisbetciorestbetcasibomgrandpashabetmatadorbetjojobetjojobetmarsbahisonwinsahabetsekabetmeritbetcasinomaxirestbetmobilbahiszbahismostbet guncel girisbetandyou guncel girisromabet guncel giris7slots guncel girisbizbet guncel girisrocksroyalbetkazandramostbetdeneme bonusu veren sitelerdeneme bonusu veren siteleristanbulkart başvuruartemisbetonwinbetgit girişprincessbethttp://nakanakadining.com/betkanyonpinup yeni girismatadorbet yeni girisroketbet yeni girisskyloft yeni girismegapari yeni girisjojobetsavoybettingcasinomhubligobetcasibomenobahisJojobetbetipusulabetbetmoontarafbetmariobetklasbahisperabetjetbetbahiscomkralbetcratosslotİstanbul Escortbahsegelkingroyalkingroyalmeritbetpinbahisjojobetzbahismostbetonwin güncel girişholiganbet girişhttps://www.escortbayanlariz.net/beylikdüzü escortfikstürbetmisliwinmarsbahis girişbets10artemisbetjojobetrotabetholiganbetgrandpashabet girişartemisbetsekabetholiganbet girişjojobetmatbet girişbets10Jojobet Girişultrabet girişprensbetcoinbarpusulabetjojobet güncel girişbetwoonjojobet girişsahabetmeritking girişmatadorbetgrandpashabet girişsahabet girişgrandpashabetsekabet girişcasibomcasibom girişholiganbetmavibetbetsmovematbetbetparkarnavutköy escortGörükle escortimajbetmavibetholiganbetbetparkholiganbetjojobetcasibommarsbahis girişvaycasino güncel giriş, vaycasino girişbakırköy escortholiganbet girişbetkanyon güncel girişsüperbetin güncel girişjojobetholiganbetholiganbetholiganbetcasibommarsbahiscasibom girişcasibomdeneme bonusu veren sitelergrandpashabetbetturkey girişbetturkeymobilbahis güncel girişhalkali escortgalabetcasinomaxi güncel girişasyabahissekabet girişmarsbahisultrabetmatadorbetmadridbetbetturkeyvaycasinobetkanyonotobettipobetfixbetdinamobetmeritkingkulisbetkralbetimajbetmostbet güncel girişmarsbahisimajbetjojobet girişpadişahbetjojobetjojobet girişsetrabetselçuksportsSekabetsekabetjojobetdeneme bonusu veren sitelerantalya escortbetturkeydumanbetfixbetsekabetbets10 girişcasibom girişgamdom girişcasibomgamdomistanbul escortbets10