Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 18005

I wrote a code to solve a quadratic equation in Java, but it doesn't work [closed]

$
0
0
import java.util.*;public class Project1 {    public static void main(String[] args) {        System.out.println("Enter a,b,c: ");        Scanner input = new Scanner(System.in);        double a1 = input.nextDouble();        double b1 = input.nextDouble();        double c1 = input.nextDouble();        Equsolve Equ = new Equsolve(a1, b1, c1);        Equ.PrintInfo();    }}

This was main class code.

this one is equation class:

public class Equsolve {    double a;    double b;    double c;    double x2;    double x1;    public Equsolve(double a1, double b1, double c1) {        a = a1;        b = b1;        c = c1;    }    public void delta() {        double delta = (b*b)-(4*a*c);    }    public void x1(double delta){        x1 = ((-b)+(Math.sqrt(delta))/(2*a));    }    public void x2(double delta){        x2 = ((-b)-(Math.sqrt(delta))/(2*a));    }    public void PrintInfo(){        System.out.format("a = %f\n", a);        System.out.format("b = %f\n", b);        System.out.format("c = %f\n", c);        System.out.format("x1 = %f\n", x1);        System.out.format("x2 = %f\n", x2);    }}

I was trying to create a class which solves quadratic equations.But the x1 and x2 are always 0!I even tried to change the value manually but it's still 0!


Viewing all articles
Browse latest Browse all 18005


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>