0
public static void quadraticEquation(double a, double b, double c) {
        // Fill your code here
        double sol2=0.00d;
        double sol1=0.00d;
        double d=(b*b) - (4*a*c);
        if (d>=0){
            sol1=(-b+Math.sqrt(d))/(2*a);
            sol2=(-b-Math.sqrt(d))/(2*a);
            return sol1,sol2;
        }else{
            System.out.println("There are no real values for solving the equation");
        }

    }// quadraticEquation

this is my code but where it says (return sol1,sol2;) it shows me this message: The primitive type double of sol1 does not have a field sol2 Also I think another thing that i got wrong is the "," but i dont know how i'm supposed to separate those in java. I'm just starting with java so I could really use any help. Thank you :) Edit: I didnt mention that i cant create a new class for that because it is an assignment that doesnt let me do that

eleanna
  • 11
  • 3
  • `return sol1,sol2;` This is a void function, meaning it doesn't return anything. – SuperStormer Apr 17 '21 at 18:50
  • you can only return one value in java. If you need to return more than one, create a class that contains these values and return an instance of that class. – f1sh Apr 17 '21 at 18:52
  • the issue is that i cant create a class because this is an assignment where I am not allowed to add classes and use only the existing ones. Also i tried using this: return new Pair<>(sol1,sol2); but I'm not sure if it's correct – eleanna Apr 17 '21 at 19:23
  • @eleanna how are you not sure? Have you tried running it? A `Pair` sounds very much like something you want to use in this case. – f1sh Apr 17 '21 at 20:19
  • yeah i had an issue while running the code and thought it was because of that, but it was because of another class. Thank for your help! – eleanna Apr 17 '21 at 21:48

0 Answers0