Question: import java.util.Scanner; public class ProjectPhase1 { public static void main(String[] args) { Scanner orsw = new Scanner(System.in); System.out.println(Enter a value for a ::); int a
import java.util.Scanner; public class ProjectPhase1 { public static void main(String[] args) { Scanner orsw = new Scanner(System.in); System.out.println("Enter a value for a ::"); int a = orsw.nextInt(); System.out.println("Enter a value for b ::"); int b = orsw.nextInt(); System.out.println("Enter a value for c ::"); int c = orsw.nextInt(); // calculate the determinant (b2 - 4ac) double discriminant = b*b - 4*a*c; double sqrt = Math.sqrt(discriminant); // check if determinant is greater than 0 if(discriminant>0) { System.out.println("The roots are real and different"); System.out.println((-b+sqrt)/(2*a)); System.out.println((-b-sqrt)/(2*a)); } // check if determinant is equal to 0 else if(discriminant==0) { System.out.println("The roots are real and equal"); System.out.println(-b/(2*a)); } // if determinant is less than zero else { System.out.println("The equation has no real root"); System.out.println(-b/(2*a)+" + "+sqrt+"i"); System.out.println(-b/(2*a)+" - "+sqrt+"i")
I need Brief description
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
