posted 11 years ago

need help in identifying the right method and return type in my program.thanks for ever listening hears.

code:

public class QuadraticEquation{

public static double Equation(int a,int b,int c){

double D,x1,x1;

//int a,b,c;

D=(Math.pow(b,2)-4*a*c);

if(D=0){

x1=(-b-Math.sqrt(D))/(2*a);

x2=(-b+Math.sqrt(D))/(2*a);

return(x1,x2);

}

}

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));

}

}

code:

public class QuadraticEquation{

public static double Equation(int a,int b,int c){

double D,x1,x1;

//int a,b,c;

D=(Math.pow(b,2)-4*a*c);

if(D=0){

x1=(-b-Math.sqrt(D))/(2*a);

x2=(-b+Math.sqrt(D))/(2*a);

return(x1,x2);

}

}

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));

}

}

posted 11 years ago

Hi all,

you cannot return multiple values. In your case you should return an array of doubles.

Your method could be like:

Yours,

Bu.

you cannot return multiple values. In your case you should return an array of doubles.

Your method could be like:

Yours,

Bu.

all events occur in real time

posted 11 years ago

There are some more bugs in your code. For example:

This is not going to do what you want. It assigns 0 to D. To compare values, use == instead of =.

Quadratic equations do not always have two solutions. What are you going to return if the equation does not have any (real) solutions (when D < 0)?

**if(D=0){**This is not going to do what you want. It assigns 0 to D. To compare values, use == instead of =.

Quadratic equations do not always have two solutions. What are you going to return if the equation does not have any (real) solutions (when D < 0)?

oghenekaro EFEKODO

Ranch Hand

Posts: 56

posted 11 years ago

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));

}

}

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));

}

}

oghenekaro EFEKODO

Ranch Hand

Posts: 56

oghenekaro EFEKODO

Ranch Hand

Posts: 56

posted 11 years ago

i added array[array.length-1] and gave an Exception in thread "main" java.lang.NoClassDefFoundError:QuadraticEquation.

so what do i do next.thanks for your ever listening hears

so what do i do next.thanks for your ever listening hears

It is sorta covered in the JavaRanch Style Guide. |