Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Quad2
- {
- private double a;
- private double b;
- private double c;
- public Quad2 (double aa, double bb, double cc)
- {
- a = aa;
- b = bb;
- c = cc;
- }
- public String getNumSolns()
- {
- if((b*b)-(4*a*c) > 0)
- {
- return "Two real solutions";
- }
- else if((b*b)-(4*a*c) == 0)
- {
- return "One real solution";
- }
- else
- {
- return "Complex Solutions";
- }
- }
- public void getSolns()
- {
- if((b*b)-4*a*c > 0)
- {
- System.out.println(getSolution1() + " " + getSolution2());
- }
- else if((b*b)-4*a*c == 0)
- {
- System.out.println(getSolution1());
- }
- else
- {
- System.out.println(-b / (2*a) + "+" + (Math.sqrt(Math.abs((b*b)-(4*a*c)) ) ) / (2*a) + "i");
- System.out.println(-b / (2*a) + "-" + (Math.sqrt(Math.abs((b*b)-(4*a*c)) ) ) / (2*a) + "i");
- }
- }
- public double getSolution1()
- {
- return (-b + Math.sqrt((b*b)-4*a*c)) / (2*a);
- }
- public double getSolution2()
- {
- return (-b - Math.sqrt((b*b)-4*a*c)) / (2*a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement