Last active
December 26, 2015 15:29
-
-
Save henvic/7173557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example; | |
import java.util.Scanner; | |
public class HelloWorld { | |
public static void main(String[] args) { | |
double a, b, c, delta; | |
double[] x = new double[2]; | |
Scanner input; | |
input = new Scanner(System.in); | |
System.out.print("a: "); | |
a = input.nextDouble(); | |
System.out.print("b: "); | |
b = input.nextDouble(); | |
System.out.print("c: "); | |
c = input.nextDouble(); | |
if (a == 0) { | |
x[0] = -c / b; | |
System.out.println("x = " + x[0]); | |
return; | |
} | |
delta = ((b * b) - (4 * a * c)); | |
if (delta < 0) { | |
System.out.println("Delta < 0"); | |
return; | |
} | |
x[0] = ((-b + (Math.sqrt(delta))) / (2 * a)); | |
x[1] = ((-b - (Math.sqrt(delta))) / (2 * a)); | |
System.out.println("x[0] = " + x[0] + ", x[1] = " + x[1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment