Calculate Circle Perimeter using Java Example

Calculate Circle Perimeter using Java Example

/*         Calculate Circle Perimeter using Java Example         This Calculate Circle Perimeter using Java Example shows how to cal

Bihar board results 2017-18 has been Declared | Bihar 12th Result 2017 | Bihar topper 2017-18
10K teaching posts vacant in KV schools
We need to focus on promoting Humanities
  1. /*
  2.         Calculate Circle Perimeter using Java Example
  3.         This Calculate Circle Perimeter using Java Example shows how to calculate
  4.         Perimeter of circle using it’s radius.
  5. */
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. public class CalculateCirclePerimeterExample {
  10.         public static void main(String[] args) {
  11.                 int radius = 0;
  12.                 System.out.println(“Please enter radius of a circle”);
  13.                 try
  14.                 {
  15.                         //get the radius from console
  16.                         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17.                         radius = Integer.parseInt(br.readLine());
  18.                 }
  19.                 //if invalid value was entered
  20.                 catch(NumberFormatException ne)
  21.                 {
  22.                         System.out.println(“Invalid radius value” + ne);
  23.                         System.exit(0);
  24.                 }
  25.                 catch(IOException ioe)
  26.                 {
  27.                         System.out.println(“IO Error :” + ioe);
  28.                         System.exit(0);
  29.                 }
  30.                 /*
  31.                  * Perimeter of a circle is
  32.                  * 2 * pi * r
  33.                  * where r is a radius of a circle.
  34.                  */
  35.                 //NOTE : use Math.PI constant to get value of pi
  36.                 double perimeter = 2 * Math.PI * radius;
  37.                 System.out.println(“Perimeter of a circle is “ + perimeter);
  38.         }
  39. }
  40. /*
  41. Output of Calculate Circle Perimeter using Java Example would be
  42. Please enter radius of a circle
  43. 19
  44. Perimeter of a circle is 119.38052083641213
  45. */

COMMENTS

WORDPRESS: 0
DISQUS: