How do I make my array legal? It doesn't seem to like my style here.
import java.util.Scanner;
public class solveQuadratic {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[2];
double[] roots = new double[3];
System.out.println("If the format is ax(sq)+bx+c=0.");
System.out.print("Enter a: ");
double a = input.nextDouble();
a = eqn[0];
System.out.print("Enter b: ");
double b = input.nextDouble();
b = eqn[1];
System.out.print("Enter c: ");
double c = input.nextDouble();
c= eqn[2];
double disc = Math.pow(eqn[1],2) - 4*eqn[0]*eqn[2];
solveQuadrat(eqn, roots);
if (disc > 0 ){
System.out.println("there are two solutions: " +roots[0]+" and "+roots[1]);
}
else if (disc == 0){
System.out.println("The solutions is: "+roots[0]);
}
else if (disc < 0){
System.out.println("The solutions are "+roots[2]+ "i" + " and "+roots[3]+ "i");
}
}
public static int solveQuadrat(double[] eqn, double[] roots) {
double disc = Math.pow(eqn[1],2) - 4*eqn[0]*eqn[2];
double uno = (-eqn[1] + Math.sqrt(disc))/(2*eqn[0]);
double dos = (-eqn[1] - Math.sqrt(disc))/(2*eqn[0]);
double i=Math.sqrt(-1);
double tres = (-eqn[1] + (Math.sqrt(Math.abs(disc))))/(2*eqn[0]);
double quat = (-eqn[1] + (Math.sqrt(Math.abs(disc))))/(2*eqn[0]);
uno = roots[0];
dos = roots[1];
tres = roots[2];
quat = roots[3];
return 0;
}
}
I can do this without arrays no problem, I don't understand arrays at all. Is there a decent tutorial online?