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

ok, so now you've posted the assignment, what is the actual problem you are having?

Line 14: write a minus sign after the -b instead of a plus sign.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.