fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. double a, b, c, x1, x2, x3, x4, t1, t2, d, D; boolean log=false;
  11. a=in.nextDouble();
  12. b=in.nextDouble();
  13. c=in.nextDouble();
  14. if (a==0) {
  15. if (b!=0) {
  16. if (c==0) {System.out.printf("X=0;");}
  17. else {
  18. if (c/b<0){
  19. x1=Math.sqrt(-(c/b));
  20. x2=-Math.sqrt(-(c/b));
  21. System.out.printf("X1=%f; X2=%f; ",x1,x2);
  22. }
  23. else {System.out.printf("Нет решений");}
  24. }
  25. }
  26. else {
  27. if (c!=0) {System.out.printf("Нет решений");}
  28. else {System.out.printf("X любое");}
  29.  
  30. }
  31. }
  32. else{
  33. D = (b * b - 4 * a * c);
  34. if (D<0) {System.out.printf("Нет решений");}
  35. else {
  36. d=Math.sqrt(D);
  37. t1=( - b + d )/2.0 / a;
  38. t2=( - b - d )/2.0 / a;
  39. if (t1>0){
  40. x1=Math.sqrt(t1);
  41. x2=-Math.sqrt(t1);
  42. System.out.printf("X1=%f; X2=%f; ",x1,x2);
  43. log = true;
  44. }
  45. if (t2>0){
  46. x3=Math.sqrt(t2);
  47. x4=-Math.sqrt(t2);
  48. if (log == true){System.out.printf("X3=%f; X4=%f; ",x3,x4);}
  49. if (log == false){System.out.printf("X1=%f; X2=%f; ",x3,x4);}
  50. }
  51. }
  52. }
  53. }
  54. }
Success #stdin #stdout 0.18s 321344KB
stdin
-5 22 -6
stdout
X1=0.540483; X2=-0.540483; X3=2.026790; X4=-2.026790;