fork(1) download
  1. import java.util.*;
  2.  
  3. class Main
  4. {
  5. public static void main (String[] args)
  6. {
  7. Scanner s = new Scanner(System.in);
  8. double A = s.nextDouble();
  9. double B = s.nextDouble();
  10. double C = s.nextDouble();
  11. double X = Math.sqrt((B*B)-4*A*C);
  12. double R1 = (-B+X)/(2*A);
  13. double R2 = (-B-X)/(2*A);
  14.  
  15. if((R1!=Double.NaN)||(R1!=Double.NEGATIVE_INFINITY)){
  16.  
  17. System.out.printf("R1 = "+"%.5f%n",R1);
  18. }
  19. else{
  20. System.out.println("Impossivel calcular");
  21. }
  22. System.out.println();
  23. if((R2!=Double.NaN)||(R2!=Double.NEGATIVE_INFINITY)){
  24. System.out.printf("R2 = "+"%.5f%n",R2);
  25. }
  26. else{
  27. System.out.println("Impossivel calcular");
  28. }
  29. }
  30. }
Success #stdin #stdout 0.07s 4386816KB
stdin
0.0 20.0 5.0
stdout
R1 = NaN

R2 = -Infinity