{"id":2027,"date":"2019-05-26T12:28:00","date_gmt":"2019-05-26T12:28:00","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2027"},"modified":"2024-08-08T20:53:19","modified_gmt":"2024-08-08T20:53:19","slug":"java-program-for-area-of-triangle","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/java-program-for-area-of-triangle\/","title":{"rendered":"Java program for area of triangle [ 2024 ]"},"content":{"rendered":"<h1>Java Program for Area of Triangle<\/h1>\r\n<p>Write a Java program to calculate the area of a triangle. The area of the triangle of base b, and height h is calculated using the mathematical formula:<\/p>\r\n<h2>Area of Triangle<\/h2>\r\n<p>Mathematical formula:<\/p>\r\n<p><img decoding=\"async\" src=\"https:\/\/latex.codecogs.com\/gif.latex?Area&amp;space;of&amp;space;Triangle&amp;space;=&amp;space;\\frac{&amp;space;base&amp;space;*&amp;space;height}{&amp;space;2}\" alt=\"Area of Triangle = \\frac{ base * height}{ 2}\" align=\"absmiddle\" title=\"\"><\/p>\r\n<h3>\u00a0<\/h3>\r\n<h2>Eclipse IDE Steps<\/h2>\r\n<p>We will use Eclipse IDE in this tutorial.\u00a0Some steps and instructions to create a Java application:<\/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<p>&nbsp;<\/p>\r\n<h2>Java Program<\/h2>\r\n<p>The Java program prompts the user to enter the base and the height of the triangle.\u00a0It computes the area of the triangle using the formula. The program displays the area to the console window.<\/p>\r\n<p>&nbsp;<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.util.Scanner;\r\n\/*****************************************************************\r\n * AreaOfTriangle.java\r\n * @program : Java program to calculate the area\r\n * @web : www.testingdocs.com\r\n * @version : 1.0\r\n ******************************************************************\/ \r\npublic class AreaOfTriangle \r\n{\r\n  public static void main(String args[]) \r\n  {   \r\n\r\n    Scanner s= new Scanner(System.in);\r\n\r\n    System.out.println(\"Enter the width of the Triangle:\");\r\n    double b= s.nextDouble();\r\n\r\n    System.out.println(\"Enter the height of the Triangle:\");\r\n    double h= s.nextDouble();\r\n\r\n    \/\/Area = (width*height)\/2\r\n    double area=(b*h)\/2;\r\n    System.out.println(\"Area of Triangle is: \" + area);      \r\n  }\r\n}\r\n<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<h2>Run the Program<\/h2>\r\n<p>Run the Java application to verify the program.\u00a0<\/p>\r\n<ul>\r\n<li>Steps to Run Java Project in Eclipse IDE<\/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>Sample Output<\/h2>\r\n<p>Enter the width of the Triangle:<br \/>45<br \/>Enter the height of the Triangle:<br \/>65<br \/>Area of Triangle is: 1462.5<\/p>\r\n<h2>Screenshot<\/h2>\r\n<p>Screenshot of the Java Application:<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2157\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/triangle.png\" alt=\"\" width=\"941\" height=\"620\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/triangle.png 941w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/triangle-300x198.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/triangle-768x506.png 768w\" sizes=\"auto, (max-width: 941px) 100vw, 941px\" \/><\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&#8212;<\/p>\r\n<h2>Java Tutorials<\/h2>\r\n<p>Java Tutorial on this website:<\/p>\r\n<p><a href=\"https:\/\/www.testingdocs.com\/java-tutorial\/\">https:\/\/www.testingdocs.com\/java-tutorial\/<\/a><\/p>\r\n<p>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<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Java Program for Area of Triangle : Write a Java program to calculate the area of a triangle. The area of the triangle of base b, and height h is calculated using<\/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":[22],"class_list":["post-2027","post","type-post","status-publish","format-standard","hentry","category-java-programs","tag-eclipse","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\/2027","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=2027"}],"version-history":[{"count":10,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2027\/revisions"}],"predecessor-version":[{"id":23566,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2027\/revisions\/23566"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}