From 774d74a9d98e1e8847489c25cd6d91e8bfd20171 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 25 Feb 2024 16:58:48 -0800 Subject: [PATCH] Commit --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ Java-Assignment-005.iml | 1 + src/Quadratic.java | 31 +++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml create mode 100644 src/Quadratic.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..172df7b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Assignment-005.iml b/Java-Assignment-005.iml index b46c0dd..e1006ff 100644 --- a/Java-Assignment-005.iml +++ b/Java-Assignment-005.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/src/Quadratic.java b/src/Quadratic.java new file mode 100644 index 0000000..a9f0037 --- /dev/null +++ b/src/Quadratic.java @@ -0,0 +1,31 @@ +import java.util.Scanner; + +public class Quadratic { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Quadratic Equation Solver"); + System.out.println("Enter the coefficients of the quadratic equation"); + + System.out.println("Enter Coefficient a: "); + double a = scanner.nextDouble(); + System.out.println("Enter Coefficient b: "); + double b = scanner.nextDouble(); + System.out.println("Enter Coefficient c: "); + double c = scanner.nextDouble(); + + double discriminant = b * b - 4 * a * c; + + if (discriminant > 0) { + double root1 = (-b + Math.sqrt(discriminant)) / (2 * a); + double root2 = (-b - Math.sqrt(discriminant)) / (2 * a); + System.out.println("Root 1: " + root1); + System.out.println("Root 2: " + root2); + } else if (discriminant == 0) { + double root = -b / (2 * a); + System.out.println("The root is: " + root); + } else { + System.out.println("The equation has no real roots."); + } + + } +} \ No newline at end of file