Skip to content

Instantly share code, notes, and snippets.

@henvic
Last active December 26, 2015 15:29
Show Gist options
  • Save henvic/7173557 to your computer and use it in GitHub Desktop.
Save henvic/7173557 to your computer and use it in GitHub Desktop.
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