0
import java.util.Scanner;
public class assignment8{
public static void  main(String[] args ){
Scanner s = new Scanner (System.in);
double a,b,c;
double discriminant, r1, r2;
System.out.print("Enter a, b,c");
a=s.nextDouble();
b=s.nextDouble();
c=s.nextDouble();
discriminant= Math.pow(b,2)- 4*a*c;
if(discriminant>0){
r1=(-b + Math.pow(discriminant,0.5))/(2*a);
r2=(-b+ Math.pow(discriminant,0.5))/(2*a);
System.out.print("The equation has two roots"+ r1 + "and"+ r2+".");
}else if(discriminant==0){
r1= (-b)/(2*a);
System.out.print("The equation has one root"+r1+".");
}else{
System.out.print("The equatiion has no real roots.");
}

Hi guys im having troule with getting the Two real roots: -2.0, 2.5
heres the the assignment

Write a program that prompts the user to enter values for a, b, and c and displays the result based on the discriminant. If the discriminant is positive, display two roots. If the discriminant is zero, display one root. If the discriminant is negative, display "The equation has no real roots".

Examples:

1 2 1

One real root: -1.0

1 1 1

No real roots

2 -1 -10

Two real roots: -2.0, 2.5

Edited by patricia28

3
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by ddanbe
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.