Get the App
SLTechnology News&Howtos  ›  Development  › 

How does java design a class for the quadratic equation ax ^ 2 + bx+c=0?

Shulou Source: shulou.com Published: 2022-06-03 15:00:43 10月01日 Update

This article mainly explains "how java designs a class for the quadratic equation ax ^ 2 + bx+c=0". The explanation in this article is simple, clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how java designs a class for the quadratic equation ax ^ 2 + bx+c=0".

Public class QuadraticEquationtest / / Test class {public static void main (String [] args) {/ / three arecedence brecedence c Quadraticequation equation1=new Quadraticequation (1.0meme3); Quadraticequation.ret (equation1); Quadraticequation equation2=new Quadraticequation (1meme2.0); Quadraticequation.ret (equation2); Quadraticequation equation3=new Quadraticequation (1mem2); Quadraticequation.ret (equation3);}} class Quadraticequation {private double a; private double b Private double c; public Quadraticequation (double XJI double YJZ) / / constructs a parameterized method {axix; baked; cymz;} public double getA () {return a;} public double getB () {return b;} public double getC () {return c } public double getDiscriminant () {return btel (getDiscriminant ());} public double getRoot1 () {return (- b+Math.sqrt (getDiscriminant () / (2yoga);} public double getRoot2 () {return (- b-Math.sqrt (getDiscriminant () / (2yoga) } public static void ret (Quadraticequation equation) / / ret method to prevent too much code {double ret1=equation.getDiscriminant (); if (ret1 > 0) {System.out.println ("The equation has two roots" + equation.getRoot1 () + "and" + equation.getRoot2 ());} else if (ret1==0) {System.out.println ("The equation has one roots" + equation.getRoot1 ()) } else {System.out.println ("The equation has no real roots") Thank you for your reading. The above is the content of "how java designs a class for the quadratic equation ax ^ 2 + bx+c=0". After the study of this article, I believe you have a deeper understanding of how java designs a class for the quadratic equation ax ^ 2 + bx+c=0, and the specific use still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Program design learning content method three code that is ideas situations articles more knowledge knowledge points articles follow too many problems practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Linux Microsoft NVidia