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..103b6ef --- /dev/null +++ b/src/Quadratic.java @@ -0,0 +1,36 @@ +/** + * + * @author Andrew Escarcega + * + * @since 2/25/2024 + * + */ +import java.util.Scanner; +public class Quadratic { + public static void main(String[] args){ + + Scanner scan = new Scanner(System.in); + System.out.println("Enter the quadratic coefficients for a, b, and c: "); + System.out.print("a: "); + int a = scan.nextInt(); + System.out.print("b: "); + int b = scan.nextInt(); + System.out.print("c: "); + int c = scan.nextInt(); + + //int d = (int) (Math.pow(b, 2) - 4 * a * c); + int d = b * b - 4 * a * c; + if (d > 0){ + double x1 = (-b + Math.sqrt(d)) / (2 * a); + double x2 = (-b - Math.sqrt(d)) / (2 * a); + System.out.print("x = "+ x1 +" and x = "+ x2); + } else if (d == 0){ + double x3 = -b / (2 * a); + System.out.println("x = "+ x3); + }else { + System.out.println("No real roots."); + } + + } + +}