{"id":1417,"date":"2022-03-03T19:37:26","date_gmt":"2022-03-03T19:37:26","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1417"},"modified":"2022-03-03T19:37:26","modified_gmt":"2022-03-03T19:37:26","slug":"program-to-calculate-area-of-square","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-calculate-area-of-square\/","title":{"rendered":"Program to calculate area of Square"},"content":{"rendered":"\n<p>In this tutorial we will learn&nbsp;<strong>how to calculate area of Square<\/strong>. Following are the two ways to do it:<\/p>\n\n\n\n<p>1) Program 1: Prompting user for entering the side of the square<br>2) Program 2: Side of the square is specified in the program\u2019 s source code.<\/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 of square.Program \n * will prompt user for entering the side of the square.\n *\/\nimport java.util.Scanner;\nclass SquareAreaDemo {\n   public static void main (String&#91;] args)\n   {\n       System.out.println(\"Enter Side of Square:\");\n       \/\/Capture the user's input\n       Scanner scanner = new Scanner(System.in);\n       \/\/Storing the captured value in a variable\n       double side = scanner.nextDouble();\n       \/\/Area of Square = side*side\n       double area = side*side; \n       System.out.println(\"Area of Square is: \"+area);\n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter Side of Square:\n2.5\nArea of Square is: 6.25<\/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 of square.\n * No user interaction: Side of square is hard-coded in the\n * program itself.\n *\/\nclass SquareAreaDemo2 {\n   public static void main (String&#91;] args)\n   {\n       \/\/Value specified in the program itself\n       double side = 4.5;\n       \/\/Area of Square = side*side\n       double area = side*side; \n       System.out.println(\"Area of Square is: \"+area);\n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Area of Square is: 20.25<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we will learn&nbsp;how to calculate area of Square. Following are the two ways to do it: 1) Program 1: Prompting user for entering the side of the square2) Program 2: Side of the square is specified in the program\u2019 s source code. Program 1: Output: Program 2: Output:<\/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\/1417"}],"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=1417"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1417\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}