i corrected my mistake and add the array method,compiled with no error,but the problem now is that the program just keep runnin with no result.please what do i do next to correct this problem. the cod again is

public class QuadraticEquation{ public static double [] Equation(int a,int b,int c){ double [] array=new double[2]; double D,x1,x2; //int a,b,c; D=(Math.pow(b,2)-4*a*c); for(int i=0;1<array.length;i++){ if(D==0){ x1=(-b-Math.sqrt(D))/(2*a); x2=(-b+Math.sqrt(D))/(2*a); } } return array; } public static void main(String arg[]){ int a=1; int b=-3; int c=2; QuadraticEquation g=new QuadraticEquation(); System.out.println(g.Equation(a,b,c)); } }

have a closer look at this line. Should not be to difficult to spot the mistake

oghenekaro EFEKODO
Ranch Hand

Joined: Oct 10, 2005
Posts: 56

posted

0

please couldn't locate the problem in

for(int i=0;i<=array.length;i++)

i tried but my best wasn't good enough.please somebody help me,am so shy for not finding what the problem really is.thanks again for your ever listening hears.

An array "array" has array.length elements in it. The first one is array[0]; the last one is array[array.length - 1]. If you try to access array[array.length], that's off the end of the array and you'll get an ArrayIndexOutOfBoundsException .