Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having trouble with displaying the positive and negative discriminant of qu

ID: 3584512 • Letter: I

Question

I am having trouble with displaying the positive and negative discriminant of quardratic equation. Can someone take a look a my code and maybe help me with what wrong with it. The question was:Write a program that prompts user to enter values for a,b,c display results based on the discriminant. If discriminant if positive, display 2 roots. If discriminant is 0 display one root. if discriminant is negative no real root. import java.util.Scanner; public class JavaCp3Ex1 { /** * @param args the command line arguments */ public static void main(String[] args) { // Create Scanner Scanner input = new Scanner (System.in); double a; double b; double c; double root1; double root2; double discriminant; System.out.println("Enter value for a"); a = input.nextDouble(); System.out.println("Enter value for b"); b = input.nextDouble(); System.out.println("Enter value for c"); c = input.nextDouble(); { discriminant = (Math.pow(b,2)-(4*a*c)); root1 = (-b + discriminant)/(2*a); root2 = (-b - discriminant)/ (2*a); root1=root1/2*a; root2=root2/2*a; } if (discriminant>0) {System.out.println("The roots of the quadratic" + " equation are " + root1 + "and" + root2); root2 = (-b - discriminant)/ (2*a); } if (discriminant<0) {System.out.println("If discriminant is 0, display one root"); root1 = (-b + discriminant)/(2*a); } else{ System.out.println("The equation has no real roots."); } } }

Explanation / Answer

discriminant = (Math.pow(b,2)-(4*a*c)); root1 = (-b + discriminant)/(2*a); root2 = (-b - discriminant)/ (2*a); if (discriminant>0) { System.out.println("The roots of the quadratic" + " equation are " + root1 + "and" + root2); } else if (discriminant