{"id":1421,"date":"2022-03-03T19:39:29","date_gmt":"2022-03-03T19:39:29","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1421"},"modified":"2022-03-03T19:39:29","modified_gmt":"2022-03-03T19:39:29","slug":"program-to-calculate-area-and-circumference-of-circle","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-calculate-area-and-circumference-of-circle\/","title":{"rendered":"Program to calculate area and circumference of circle"},"content":{"rendered":"\n<p>In this tutorial we will see&nbsp;<strong>how to calculate area and circumference of circle in Java<\/strong>. There are two ways to do this:<\/p>\n\n\n\n<p>1) With user interaction: Program will prompt user to enter the radius of the circle<br>2) Without user interaction: The radius value would be specified in the program itself.<\/p>\n\n\n\n<p><strong>Program 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * @author: BeginnersBook.com\n * @description: Program to calculate area and circumference of circle\n * with user interaction. User will be prompt to enter the radius and \n * the result will be calculated based on the provided radius value.\n *\/\nimport java.util.Scanner;\nclass CircleDemo\n{\n   static Scanner sc = new Scanner(System.in);\n   public static void main(String args&#91;])\n   {\n      System.out.print(\"Enter the radius: \");\n      \/*We are storing the entered radius in double\n       * because a user can enter radius in decimals\n       *\/\n      double radius = sc.nextDouble();\n      \/\/Area = PI*radius*radius\n      double area = Math.PI * (radius * radius);\n      System.out.println(\"The area of circle is: \" + area);\n      \/\/Circumference = 2*PI*radius\n      double circumference= Math.PI * 2*radius;\n      System.out.println( \"The circumference of the circle is:\"+circumference) ;\n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the radius: 1\nThe area of circle is: 3.141592653589793\nThe circumference of the circle is:6.283185307179586<\/code><\/pre>\n\n\n\n<p><strong>Program 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * @author: BeginnersBook.com\n * @description: Program to calculate area and circumference of circle\n * without user interaction. You need to specify the radius value in \n * program itself.\n *\/\nclass CircleDemo2\n{\n   public static void main(String args&#91;])\n   {\n      int radius = 3;\n      double area = Math.PI * (radius * radius);\n      System.out.println(\"The area of circle is: \" + area);\n      double circumference= Math.PI * 2*radius;\n      System.out.println( \"The circumference of the circle is:\"+circumference) ;\n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The area of circle is: 28.274333882308138\nThe circumference of the circle is:18.84955592153876<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will see&nbsp;how to calculate area and circumference of circle in Java. There are two ways to do this: 1) With user interaction: Program will prompt user to enter the radius of the circle2) Without user interaction: The radius value would be specified in the program itself. Program 1: Output: Program 2: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[570],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1421"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1421"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1421\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}