Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created February 17, 2017 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folivetti/af755b9d59017001902ff51bcc328fc2 to your computer and use it in GitHub Desktop.
Save folivetti/af755b9d59017001902ff51bcc328fc2 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
double A, B, C;
double delta, R1, R2;
Scanner sc = new Scanner(System.in);
A = sc.nextDouble();
B = sc.nextDouble();
C = sc.nextDouble();
delta = B*B - 4*A*C;
if (delta < 0 || A == 0) {
System.out.println("Impossivel calcular");
} else {
R1 = (-B + Math.sqrt(delta)) / (2*A);
R2 = (-B - Math.sqrt(delta)) / (2*A);
System.out.printf("R1 = %.5f\n", R1);
System.out.printf("R2 = %.5f\n", R2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment