180k views
4 votes
Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, that determines whether the value of "b squared" – 4ac is negative. If negative, the code prints out the message "no real solutions" and returns from the method

User Tehnyit
by
8.6k points

2 Answers

6 votes

Answer:

The solution code is written in Java:

  1. public static boolean check_discriminant(double a, double b, double c)
  2. {
  3. double discriminant = b * b - (4 * a * c);
  4. if(discriminant > 0){
  5. return true;
  6. }
  7. else{
  8. System.out.println("no real solutions");
  9. return false;
  10. }
  11. }

Step-by-step explanation:

Firstly, we define a function check_discriminant() that takes three parameters with double type, a, b and c (Line 1).

Next, we calculate the discriminant using the formula b² - 4ac (Line 3). We place the discriminant in if condition (Line 5) to see if it is a negative or positive value. If positive return true (Line 6) and if negative it will print out message "no real solutions" and return false (Line 9 -10).

User Compcobalt
by
7.9k points
3 votes

Answer and Explanation:

class Dis

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter values for a,b,c");

double a=sc.nextDouble();

double b=sc.nextDouble();

double c=sc.nextDouble();

String s=discriminant(a,b,c);

System.out.println(s);

}

public String discriminant(double a, double b, double c)

{

double result;

result=(
b^2-4ac);

if(result<0)

return "no real solutions"";

else return "";

}

}

Note:This program is written in JAVA

User Moshtaf
by
7.8k points