fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. double alfa = 2.0;
  13. double beta = 18.0;
  14.  
  15. double resultValueOne = valueOne(alfa, beta);
  16.  
  17. alfa = 0.0;
  18. double resultValueTwo = valueTwo(alfa, beta);
  19.  
  20. if(Double.isNaN(resultValueOne))
  21. {
  22. System.out.println("No resultValueOne");
  23. }
  24. if(Double.isNaN(resultValueTwo))
  25. {
  26. System.out.println("No resultValueTwo");
  27. }
  28. }
  29.  
  30. public static double valueOne(double alfa, double beta)
  31. {
  32. // At least one of the values is invalid.
  33. if (Double.isNaN(alfa) || Double.isNaN(beta))
  34. {
  35. return Double.NaN;
  36. }
  37.  
  38. // Check the alpha or otherwise a div/0 exception may be thrown.
  39. if (alfa == 0.0)
  40. {
  41. return Double.NaN;
  42. }
  43.  
  44. double divResult = (-beta)/alfa;
  45.  
  46. // Check the div result because Math.sqrt accepts only positive values:
  47. // If the argument is NaN or less than zero, the result is NaN.
  48. if (divResult < 0.0)
  49. {
  50. return Double.NaN;
  51. }
  52.  
  53. return (-(Math.sqrt(divResult)))+alfa;
  54. }
  55.  
  56. public static double valueTwo(double alfa, double beta)
  57. {
  58. // At least one of the values is invalid.
  59. if (Double.isNaN(alfa) || Double.isNaN(beta))
  60. {
  61. return Double.NaN;
  62. }
  63.  
  64. // Check the alpha or otherwise a div/0 exception may be thrown.
  65. if (alfa == 0.0)
  66. {
  67. return Double.NaN;
  68. }
  69.  
  70. double divResult = (-beta)/alfa;
  71.  
  72. // Check the div result because Math.sqrt accepts only positive values:
  73. // If the argument is NaN or less than zero, the result is NaN.
  74. if (divResult < 0.0)
  75. {
  76. return Double.NaN;
  77. }
  78.  
  79. return ((Math.sqrt(divResult)))+alfa;
  80. }
  81. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
No resultValueOne
No resultValueTwo