Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report