while (true) { println (); println ("This program gives both solutions to a quadratic equation and its roots."); println (" Example: 5x^2 + 7x - 8 "); println (); //Prints the explanation of the program and an example of the format double A = readDouble(" How many x^2? (5 in the example) "); double B = readDouble(" How many x? (7 in the example) "); double C = readDouble(" How many units? (-8 in the example) "); println (); //Requests user input double Totalpositive = (-B + (Math.sqrt ((B*B) - (4*A*C)))) / (2*A); double Totalnegative = (-B - (Math.sqrt ((B*B) - (4*A*C)))) / (2*A); //Solves for both solutions of the quadratic, using the quadratic formula println ("Solution one ----> " + Totalpositive ); println ("Solution two ----> " + Totalnegative ); println (); println ("Roots: "); println (); println (" [ X + " + -Totalpositive + " ; X + " + -Totalnegative + " ]"); //Prints the solutions and the roots } }
Sabtu, November 23, 2013
JAVA - Quadratic equation
Label:
JAVA,
Matematik,
Pengaturcaraan
Langgan:
Catat Ulasan (Atom)
0 ulasan:
Catat Ulasan
Selamat datang ke 0x2013LΣΣT. Sekiranya anda mempunyai persoalan, pandangan, permintaan, bantuan, cadangan dan sebagainya. Tinggalkan pesanan anda ke dalam kotak komen. Terima kasih !
- http://0x2013.blogspot.com -