Jeisa
Member
- May 4, 2011
- 112
- 2
READ ENTIRE POST (please)
I've posted about this before, but I just demonstrated how the program worked, I also have this in Python but I am releasing the Java version. If you want the one coded in Python let me know. Anyways here's the source code, if you could compile this into an executable jar and post here, that would be great. Thanks!
Pastebin source code :
Actual source :
How this works : All you have to do is plugin the variables a,b,c and it gives you the roots to the quadratic. If you don't know what quadratics are, then please head on to this wiki.
Anyways, I hope this will be useful to all of you, also I am developing another program which solves all the most common used equations, if you would like to know more about this left me know.
Note: I coded this for my own use, and I think it is badly coded because I just started learning java a week ago, and if it is, tell me where I could improve code in.
I've posted about this before, but I just demonstrated how the program worked, I also have this in Python but I am releasing the Java version. If you want the one coded in Python let me know. Anyways here's the source code, if you could compile this into an executable jar and post here, that would be great. Thanks!
Pastebin source code :
You must be registered for see links
Actual source :
Code:
package quadratics;
import java.io.*;
import java.util.*;
public class Quadratics {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double a,b,c,twoa;
double discriminant;
System.out.println("Enter value of a : ");
a = scan.nextDouble();
System.out.println("Enter value of b : ");
b = scan.nextDouble();
System.out.println("Enter value of c : ");
c = scan.nextDouble();
discriminant = b*b-(4*a*c);
twoa = 2*a;
if (discriminant < 0 ) {
System.out.println("Since your discriminant is negative, (" + discriminant + ") There are no roots.");
} else {
double formulaplus, formulaminus, plusfin, minusfin;
formulaplus = -b + Math.sqrt(discriminant);
plusfin = formulaplus/twoa;
formulaminus = -b - Math.sqrt(discriminant);
minusfin = formulaminus/twoa;
System.out.println("Your roots are\n" + plusfin + "\n" + minusfin);
System.out.println("Discriminant = " + discriminant);
}
}
}
How this works : All you have to do is plugin the variables a,b,c and it gives you the roots to the quadratic. If you don't know what quadratics are, then please head on to this wiki.
You must be registered for see links
Anyways, I hope this will be useful to all of you, also I am developing another program which solves all the most common used equations, if you would like to know more about this left me know.
Note: I coded this for my own use, and I think it is badly coded because I just started learning java a week ago, and if it is, tell me where I could improve code in.