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..e354d06 --- /dev/null +++ b/src/Quadratic.java @@ -0,0 +1,40 @@ +import java.util.Scanner; +public class Quadratic { + static int inputA = 0; + static int inputB = 0; + static int inputC = 0; + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Give an input for a, b, c"); + System.out.print("a= "); + inputA = scanner.nextInt(); + System.out.print("b= "); + inputB = scanner.nextInt(); + System.out.print("c= "); + inputC = scanner.nextInt(); + quadFormula(); + } + + public static void quadFormula() { + double formulaInSqrt = ((Math.pow(inputB, 2)) - (4 * inputA * inputC)); + double negB = (-1 * inputB); + if (inputA == 0) { + System.out.println("Can't input 0 for a"); + return; + } + double overTwoA = ((double) 1 / (2 * inputA)); + //(-)b +- sqrt(b^2 -4(a)(c)))/2*a DONE + if (formulaInSqrt >= 0) { + double solutionOne = (((negB) + Math.sqrt(formulaInSqrt)) * (overTwoA)); + double solutionTwo = (((negB) - Math.sqrt(formulaInSqrt)) * (overTwoA)); + if(solutionOne == solutionTwo) { + System.out.println("Answer (1 solution):" + solutionOne); + } else{ + System.out.println("Answer:" + solutionOne + " & " + solutionTwo); + } + } else { + System.out.println("Imaginary radical"); + } + } +} \ No newline at end of file