"QuadricEquation testDome" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "QuadricEquation testDome" answered properly. Developers are finding an appropriate answer about QuadricEquation testDome related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like QuadricEquation testDome. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on QuadricEquation testDome. 

QuadricEquation testDome

By Victorious VendaceVictorious Vendace on Mar 24, 2021
public class QuadraticEquation {
    public static Roots findRoots(double a, double b, double c) {
    	Roots root = new Roots(0,0);
    	double root1, root2;
    	if(a==0 ||b==0||c==0) return root;
    	// calculate the determinant (b2 - 4ac)
        double determinant = (b * b) - (4 * a * c);
        if (determinant > 0) {
            // two real and distinct roots
            root1 = (-b + Math.sqrt(determinant)) / (2 * a);
            root2 = (-b - Math.sqrt(determinant)) / (2 * a);
//           System.out.format("root1 = %.2f and root2 = %.2f", root1, root2);
          } // check if determinant is equal to 0
       	else if (determinant == 0) {
           // two real and equal roots then determinant is equal to 0
            // so -b + 0 == -b
            root1 = -b / (2 * a);
            root2 = root1;
          } else {
            // roots are complex number and distinct
            root1= -b / (2 * a);
            root2 = Math.sqrt(-determinant) / (2 * a);
          }
        root = new Roots(root1,root2);
    	return root;
    }
    
    public static void main(String[] args) {
        Roots roots = QuadraticEquation.findRoots(2, 10, 8);
        System.out.println("Roots: " + roots.x1 + ", " + roots.x2);
//        roots = QuadraticEquation.findRoots(15, 68, 3);
//        System.out.println("Roots: " + roots.x1 + ", " + roots.x2);
      roots = QuadraticEquation.findRoots(1, -18, 81);
      System.out.println("Roots: " + roots.x1 + ", " + roots.x2);

    }
}

class Roots {
    public final double x1, x2;

    public Roots(double x1, double x2) {         
        this.x1 = x1;
        this.x2 = x2;
    }
}

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on QuadricEquation testDome can get a collection of related answers to their query. Programmers need to enter their query on QuadricEquation testDome related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about QuadricEquation testDome for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of QuadricEquation testDome while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "QuadricEquation testDome". Visit this developer's friendly online web community, CodeProZone, and get your queries like QuadricEquation testDome resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "QuadricEquation testDome"

View All Whatever queries

Whatever queries related to "QuadricEquation testDome"

Browse Other Code Languages

CodeProZone