From b63457bf67855b6cf2e641b5197f5b47058c3993 Mon Sep 17 00:00:00 2001 From: realjackcrew <98656977+realjackcrew@users.noreply.github.com> Date: Thu, 3 Oct 2024 23:10:55 -0400 Subject: [PATCH 1/2] implemented bhaskara theorem algorithm --- .../algorithms/math/Bhaskara.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/williamfiset/algorithms/math/Bhaskara.java diff --git a/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java b/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java new file mode 100644 index 000000000..25ce5bd30 --- /dev/null +++ b/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java @@ -0,0 +1,37 @@ +package org.example; + +public class Bhaskara { + public static void calculateRoots(double a, double b, double c) { + + // Calculate the discriminant + double discriminant = b * b - 4 * a * c; + System.out.println(discriminant); + + // Check if the discriminant is negative, zero, or positive + if (discriminant < 0) { + // No real roots + System.out.println("There are no real roots."); + + } else if (discriminant == 0) { + // One real root + double x = -b / (2 * a); + System.out.println("There is one real root: " + x); + + } else { + // Two real roots + double x1 = (-b + Math.sqrt(discriminant)) / (2 * a); + double x2 = (-b - Math.sqrt(discriminant)) / (2 * a); + System.out.println("There are two real roots: x1 = " + x1 + ", x2 = " + x2); + } + } + + public static void main(String[] args) { + + // Example using formula ax²+bx+c + + double a = 4; + double b = 20; + double c = 12; + calculateRoots(a, b, c); // Calling the Bhaskara method + } +} \ No newline at end of file From 2ae6b555e32150c95baca868fa80c29fda4474ca Mon Sep 17 00:00:00 2001 From: realjackcrew <98656977+realjackcrew@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:49:06 -0400 Subject: [PATCH 2/2] implemented Bhaskara Algorithm --- .../algorithms/math/Bhaskara.java | 60 +++++++++---------- startup | 0 2 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 startup diff --git a/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java b/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java index 25ce5bd30..054eea9cf 100644 --- a/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java +++ b/src/main/java/com/williamfiset/algorithms/math/Bhaskara.java @@ -1,37 +1,37 @@ package org.example; public class Bhaskara { - public static void calculateRoots(double a, double b, double c) { - - // Calculate the discriminant - double discriminant = b * b - 4 * a * c; - System.out.println(discriminant); - - // Check if the discriminant is negative, zero, or positive - if (discriminant < 0) { - // No real roots - System.out.println("There are no real roots."); - - } else if (discriminant == 0) { - // One real root - double x = -b / (2 * a); - System.out.println("There is one real root: " + x); - - } else { - // Two real roots - double x1 = (-b + Math.sqrt(discriminant)) / (2 * a); - double x2 = (-b - Math.sqrt(discriminant)) / (2 * a); - System.out.println("There are two real roots: x1 = " + x1 + ", x2 = " + x2); - } + public static void calculateRoots(double a, double b, double c) { + + // Calculate the discriminant + double discriminant = b * b - 4 * a * c; + + + // Check if the discriminant is negative, zero, or positive + if (discriminant < 0) { + // No real roots + System.out.println("There are no real roots."); + + } else if (discriminant == 0) { + // One real root + double x = -b / (2 * a); + System.out.println("There is one real root: " + x); + + } else { + // Two real roots + double x1 = (-b + Math.sqrt(discriminant)) / (2 * a); + double x2 = (-b - Math.sqrt(discriminant)) / (2 * a); + System.out.println("There are two real roots: x1 = " + x1 + ", x2 = " + x2); } + } - public static void main(String[] args) { + public static void main(String[] args) { - // Example using formula ax²+bx+c + // Example using formula ax²+bx+c - double a = 4; - double b = 20; - double c = 12; - calculateRoots(a, b, c); // Calling the Bhaskara method - } -} \ No newline at end of file + double a = 2; + double b = 4; + double c = 2; + calculateRoots(a, b, c); // Calling the Bhaskara method + } +} diff --git a/startup b/startup new file mode 100644 index 000000000..e69de29bb