java - Quadratic Formula Failing when A > 1? -
I am in the process of developing my first app which resolves the quadratial formula and I participated in such a problem The app that gives the incorrect answer for the roots when the value for 1 is greater than 1. This code is:
package com.example.firstapp; Import java.lang.Math; Importroid.os.Bundle; Import android App Import android.view.Menu; Import android.view.View; Import android.widget.EditText; Import android.widget.TextView; Public classroom enhances main activity activity {@ Override Protected Zero (Bundled Saved Instance) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); } Calculation of Public Zero (see V) {edit test number 1 text = (edit text) searchWBIID (RIDA); Edit Test Number 2 Text = (Editing Text) SearchVBIID (RIDB); Edit Text Number 3 Text = (Editing Text) Search ViviBid (RIDC); Double number 1 = double. PRDABB (number1 textgate text) () String ()), num2 = double. PRSD double (number 2 text .gettext (). ToString ()), number 3 = double. PRSD Double (Number 3 text .gettext (.) ToString ()); If ((num2 * num2) - (4 * num1 * num3) & lt; 0) {} double ans = (double) ((- (num2) - (math.Sqrt (num2 * num2 - (4 * num1 * num3 )))) / 2 * number 1); Double ans2 = (double) (((- (num2) + Math.sqrt (num2 * num2 - (4 * num1 * num3)))) / 2 * num1); TextView answer = (TextView) findViewById (R.id.ans1); Answer.setText ("first root:" + ans); TextView answer2 = (TextView) findViewById (R.id.ans2); Answer2.setText ("The second root is:" + ans2); } Private text view text (string string) {// TODO auto generated method stub returns empty; } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Expand Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fluo (R. menu menu, menu); Back true; = "Post-text" itemprop = "text"> The correct formula is -b ± sqrt (b ^ 2 - 4ac) / (2a)
You have -b ± sqrt (b ^ 2 - 4ac) / 2 * a
bracket 2 * num1
< / Div>
Comments
Post a Comment