Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package Lesson7;
  2.  
  3. /**
  4. * Java Start. Group 77. Home work. Lesson 7. Task 3 (CircleArea).
  5. *
  6. * @author Khilchenko Sergii
  7. * @version 0.1.0 05.15.2018
  8. *
  9. */
  10.  
  11. public class CircleArea {
  12. public static void main(String[] args) {
  13. System.out.println("CircleArea");
  14.  
  15. double radius = -10;
  16. System.out.println("RADIUS: " + radius );
  17. System.out.println("Result: " + circleArea(radius));
  18. }
  19.  
  20. public static double circleArea(double radius) {
  21. if (radius <= 0) {
  22. throw new IllegalArgumentException(" INPUT radius 0 <= ");
  23. }
  24. //return Math.PI * radius * radius;
  25. return Math.PI * Math.pow(radius, 2);
  26. }
  27. }
  28.  
  29. /*
  30. - - - - - - - - - - - - - - - - - -
  31. TEST 1
  32. CircleArea
  33. RADIUS: 10.0
  34. Result: 314.1592653589793
  35.  
  36. Process finished with exit code 0
  37. - - - - - - - - - - - - - - - - - -
  38. TEST 2
  39. CircleArea
  40. RADIUS: 20.0
  41. Result: 1256.6370614359173
  42.  
  43. Process finished with exit code 0
  44. - - - - - - - - - - - - - - - - - -
  45. TEST 3
  46. CircleArea
  47. Exception in thread "main" java.lang.IllegalArgumentException: INPUT radius 0 <=
  48. at Lesson7.CircleArea.circleArea(CircleArea.java:22)
  49. at Lesson7.CircleArea.main(CircleArea.java:17)
  50. RADIUS: -10.0
  51.  
  52. Process finished with exit code 1
  53. - - - - - - - - - - - - - - - - - -
  54. */
Add Comment
Please, Sign In to add comment