fork download
  1. /* My Java program */
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5. class MyLab
  6. { public static void main (String[] args) throws java.lang.Exception
  7. { final double K=22.50; final double L=7.5; double x=0.0; double a=0.0; double b=0.0; double y=0.0;
  8. System.out.println("Plese enter value for X\n");
  9. Scanner in = new Scanner(System.in);
  10. x=in.nextDouble();
  11. System.out.println(x);
  12. in.close();
  13. if (x<0)
  14. {
  15. System.out.println("ERROR: the negative value in log or in square root\n");
  16. }
  17. else
  18. {
  19. if (Math.sqrt(x+2.84)<0)
  20. {System.out.println("ERROR: the negative value in square root\n");
  21. }
  22. else
  23. {
  24. a=Math.pow((Math.pow(K,(-0.5))-L*Math.sqrt(x+2.84)),2);
  25. System.out.println("Result is A="+a);
  26. }
  27. }
  28. if (x<=0)
  29. {
  30. System.out.println("ERROR: the negative value or zero value in lg\n");
  31. }
  32. else
  33. {
  34. b = -Math.log10(x) * Math.exp(x);
  35. System.out.println("Result is B="+b);
  36. }
  37. if (a>b)
  38. {
  39. y = (4*a+3*b)/(Math.pow(a, 2) + Math.pow(b, 2));
  40. }
  41. if (a<=b)
  42. {
  43. if (Math.pow(a, 2) + Math.pow(b, 2)==0) {
  44. System.out.println("ERROR: division by zero\n");
  45. }
  46. if (a<=0) {
  47. y = Math.abs(a - b);
  48. System.out.println("Result is Y="+y);
  49. }}
  50. }
  51. }
Success #stdin #stdout 0.17s 60912KB
stdin
-0.414
stdout
Plese enter value for X

-0.414
ERROR: the negative value in log or in square root

ERROR: the negative value or zero value in lg

ERROR: division by zero

Result is Y=0.0