{"id":1920,"date":"2019-04-29T09:50:00","date_gmt":"2019-04-29T09:50:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=1920"},"modified":"2024-08-08T20:59:32","modified_gmt":"2024-08-08T20:59:32","slug":"write-a-java-program-to-calculate-area-of-rectangle","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/write-a-java-program-to-calculate-area-of-rectangle\/","title":{"rendered":"Write a Java program to calculate Area of Rectangle [ 2024 ]"},"content":{"rendered":"<h2>Write a Java program to calculate Area of Rectangle<\/h2>\r\n<p>Write a Java program to calculate the Area of the Rectangle. On this page, we will write a Java program to calculate the area of the rectangle. Before writing the program, we will analyze the<\/p>\r\n<h3>IPO chart<\/h3>\r\n<h4>Input<\/h4>\r\n<p>Length, Width<\/p>\r\n<h4>Process<\/h4>\r\n<p>Area of Rectangle = Length x Width<\/p>\r\n<h4>Output\u00a0<\/h4>\r\n<p>Area\u00a0<\/p>\r\n<h3>Formula<\/h3>\r\n<p>Area = length*width<\/p>\r\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1922 size-full\" title=\"Area of Rectangle\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Java-Program.png\" alt=\"Area of Rectangle\" width=\"1167\" height=\"600\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Java-Program.png 1167w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Java-Program-300x154.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Java-Program-1024x526.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Java-Program-768x395.png 768w\" sizes=\"auto, (max-width: 1167px) 100vw, 1167px\" \/><\/h3>\r\n<h3>Tools Used<\/h3>\r\n<p>We will use the below tools to develop the program.\u00a0<\/p>\r\n<ul>\r\n<li><strong>JDK ( Java Development Kit)<\/strong><\/li>\r\n<li><strong>Eclipse IDE( Integrated Development Environment)\u00a0<\/strong><\/li>\r\n<\/ul>\r\n<h2>Eclipse IDE<\/h2>\r\n<p>Some steps and instructions to create a Java application on Eclipse IDE:<\/p>\r\n<ul>\r\n<li>Create Java Project in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/create-a-new-java-project-in-eclipse\/<\/a><\/p>\r\n<ul>\r\n<li>Create Java Package in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/\">https:\/\/www.testingdocs.com\/create-java-package-in-eclipse-ide\/<\/a><\/p>\r\n<ul>\r\n<li>Create Java Class in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/\">https:\/\/www.testingdocs.com\/create-a-new-java-class-in-a-project\/<\/a><\/p>\r\n<ul>\r\n<li>Run Java Project in Eclipse<\/li>\r\n<\/ul>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/\">https:\/\/www.testingdocs.com\/run-java-project-in-eclipse\/<\/a><\/p>\r\n<h2><br \/>Java Program<\/h2>\r\n<p>The program prompts the user to enter the length and the width. The program uses the Scanner class to read the values from the keyboard. The variables are declared as <strong>double<\/strong> data types.\u00a0<\/p>\r\n<p>The program calculates the area as per the mathematical formula and displays the result to the screen.\u00a0<\/p>\r\n<p>Launch IDE and create a Java class.<\/p>\r\n<p>Enter the program code.\u00a0<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/**************************************************\r\n * AreaOfRectangle.java\r\n * @program : Area of Rectangle\r\n * @web    :  www.TestingDocs.com\r\n * @author    :  \r\n * @version   : 1.0\r\n **************************************************\/\r\n\r\nimport java.util.*;\r\n\r\npublic class AreaOfRectangle \r\n{\r\n  public static void main(String arg[ ]) \r\n  {\r\n    Scanner keyboard = new Scanner(System.in);\r\n    double length, width, areaRectangle;\r\n    System.out.print(\"Enter Length := \");\r\n    length = keyboard.nextDouble();\r\n    System.out.print(\"Enter Width := \");\r\n    width = keyboard.nextDouble();\r\n    areaRectangle = length * width;\r\n    System.out.println(\"Area of Rectangle = \"+ areaRectangle);\r\n  }\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<h3>Screenshot<\/h3>\r\n<p>Screenshot of the code in the IDE window.\u00a0<\/p>\r\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1921\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Code.png\" alt=\"\" width=\"1365\" height=\"706\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Code.png 1365w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Code-300x155.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Code-1024x530.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Area-Of-Rectangle-Code-768x397.png 768w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/h3>\r\n<h3>Sample Output<\/h3>\r\n<p>Save and Run the program from the IDE. Execute some test cases to verify the output of the program.\u00a0<\/p>\r\n<p>Right Click and choose <strong>Run as &gt;&gt; Java Application<\/strong><\/p>\r\n<p><strong>Output<\/strong><\/p>\r\n<p>Enter Length := 5<br \/>Enter Width := 3<br \/>Area of Rectangle = 15<\/p>\r\n<h2>Java Tutorials<\/h2>\r\n<p>Java Tutorial on this website:<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/li>\r\n<\/ul>\r\n<p><br \/>For more information on Java, visit the official website :<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.oracle.com\/in\/java\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.oracle.com\/in\/java\/<\/a><\/li>\r\n<\/ul>\r\n","protected":false},"excerpt":{"rendered":"<p>Write a Java program to calculate Area of Rectangle Write a Java program to calculate the Area of the Rectangle. On this page, we will write a Java program to calculate the area of the rectangle. Before writing the program, we will analyze the IPO chart Input Length, Width Process Area of Rectangle = Length [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[24],"class_list":["post-1920","post","type-post","status-publish","format-standard","hentry","category-java-programs","tag-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=1920"}],"version-history":[{"count":10,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1920\/revisions"}],"predecessor-version":[{"id":23574,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1920\/revisions\/23574"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=1920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=1920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=1920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}