I've tried creating codes to solve a quadratic formula but I've only succeeded in creating it for a specific formula. Is there any way I can be providing the variables a, b, c by user input then the solution prints out? The program also refuses to run on command prompt but can run in eclipse. What might be the issue?
Here it is.
public class Equationsolver {
public static void main(String[] args) {
double a, b, c;
a = 2;
b = 6;
c = 4;
double disc = Math.pow(b,2) - 4*a*c;
double soln1 = (-b + Math.sqrt(disc)) / (2*a) ;
double soln2 = (-b - Math.sqrt(disc)) / (2*a);
if (disc >= 0) {
System.out.println("soln1 = " + soln1);
System.out.println("soln2 = " + soln2);
}else{
System.out.println("equation has no real roots");
}
}
}