{"id":1419,"date":"2022-03-03T19:38:19","date_gmt":"2022-03-03T19:38:19","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1419"},"modified":"2022-03-03T19:38:19","modified_gmt":"2022-03-03T19:38:19","slug":"program-to-calculate-area-of-triangle","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-calculate-area-of-triangle\/","title":{"rendered":"Program to calculate area of Triangle"},"content":{"rendered":"\n<p>Here we will see how to calculate area of triangle. We will see two following programs to do this:<br>1) Program 1: Prompt user for base-width and height of triangle.<br>2) Program 2: No user interaction: Width and height are 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 of Triangle in Java\n * with user interaction. Program will prompt user to enter the \n * base width and height of the triangle.\n *\/\nimport java.util.Scanner;\nclass AreaTriangleDemo {\n   public static void main(String args&#91;]) {   \n      Scanner scanner = new Scanner(System.in);\n\n      System.out.println(\"Enter the width of the Triangle:\");\n      double base = scanner.nextDouble();\n\n      System.out.println(\"Enter the height of the Triangle:\");\n      double height = scanner.nextDouble();\n\n      \/\/Area = (width*height)\/2\n      double area = (base* height)\/2;\n      System.out.println(\"Area of Triangle is: \" + area);      \n   }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the width of the Triangle:\n2\nEnter the height of the Triangle:\n2\nArea of Triangle is: 2.0<\/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 Triangle\n * with no user interaction.\n *\/\nclass AreaTriangleDemo2 {\n   public static void main(String args&#91;]) {   \n      double base = 20.0;\n      double height = 110.5;\n      double area = (base* height)\/2;\n      System.out.println(\"Area of Triangle 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 Triangle is: 1105.0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here we will see how to calculate area of triangle. We will see two following programs to do this:1) Program 1: Prompt user for base-width and height of triangle.2) Program 2: No user interaction: Width and height are specified in the program itself. 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\/1419"}],"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=1419"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1419\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}