From e61d0f76d4e78f0a4c0dd63a9acc08a180c2832d Mon Sep 17 00:00:00 2001 From: Jaime Ortiz Date: Fri, 23 Feb 2024 22:47:46 -0800 Subject: [PATCH 1/2] finished assignment-005 --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ Java-Assignment-005.iml | 1 + src/Quadratic.java | 30 ++++++++++++++++++++++++++++++ 4 files changed, 38 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..cbbff6a 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..3025640 --- /dev/null +++ b/src/Quadratic.java @@ -0,0 +1,30 @@ +import java.util.Scanner; +public class Quadratic { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter three integers (a, b, c) for the quadratic equation ax^2 + bx + c = 0:"); + + int a = scanner.nextInt(); + int b = scanner.nextInt(); + int c = scanner.nextInt(); + + if (a == 0) { + System.out.println("Error: 'a' must not be zero."); + } else { + double discriminant = Math.pow(b, 2) - 4 * a * c; + + if (discriminant < 0){ + System.out.println("Error: The equation has no real roots."); + } else if (discriminant ==0){ + double root = -b / (2.0 * a); + System.out.println("The equation has one root: " + root); + } else { + double root1 = (-b + Math.sqrt(discriminant)) / (2 * a); + double root2 = (-b - Math.sqrt(discriminant)) / (2 * a); + System.out.println("The equation has two roots: " + root1 + " and " + root2); + } + } + } + +} From 5dad15076f58816a3c88c89a9b370ed644d6d9da Mon Sep 17 00:00:00 2001 From: Jaime Ortiz Date: Fri, 23 Feb 2024 22:49:47 -0800 Subject: [PATCH 2/2] finished assignment-005 --- src/Quadratic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quadratic.java b/src/Quadratic.java index 3025640..1588579 100644 --- a/src/Quadratic.java +++ b/src/Quadratic.java @@ -3,7 +3,7 @@ public class Quadratic { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); - System.out.println("Enter three integers (a, b, c) for the quadratic equation ax^2 + bx + c = 0:"); + System.out.println("Enter three integers (a, b, c) for the quadratic equation ax^2 + bx + c = 0: "); int a = scanner.nextInt(); int b = scanner.nextInt();