document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class CalculateCircleAreaExample {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. int radius = 0;
  10. System.out.println("Please enter radius of a circle");
  11.  
  12. try
  13. {
  14. //get the radius from console
  15. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  16. radius = Integer.parseInt(br.readLine());
  17. }
  18. //if invalid value was entered
  19. catch(NumberFormatException ne)
  20. {
  21. System.out.println("Invalid radius value" + ne);
  22. System.exit(0);
  23. }
  24. catch(IOException ioe)
  25. {
  26. System.out.println("IO Error :" + ioe);
  27. System.exit(0);
  28. }
  29.  
  30. /*
  31. * Area of a circle is
  32. * pi * r * r
  33. * where r is a radius of a circle.
  34. */
  35.  
  36. //NOTE : use Math.PI constant to get value of pi
  37. double area = Math.PI * radius * radius;
  38.  
  39. System.out.println("Area of a circle is " + area);
  40. }
  41. }
');