Public static double CalculateArea(double side1, double side2, double side3)Īrea = Math. ("\n The Area of the triangle = %.2f\n",area) ("\n Enter the three sides of the triangle: ") Īrea = CalculateArea(side1, side2, side3) Use heron's formula to calculate the area.Before writing the program we will analyze the. Call the method and return the calculated area. If we know the width and height of a rectangle, we can calculate the area of a rectangle using the formula: Area Width Height. On this page, we will write a java program to calculate the area of the rectangle.Use a user-defined method to calculate the area of the triangle.In this program, we will see how to calculate the area of a triangle when three sides are given using a user-defined method. Program 2: Java Program to find Area of a Triangle when Three Sides are Given ("\n The Area of the triangle = %.2f\n",Area) Įnter the Three sides of the triangle: 5 6 7 ("\n The Semi Perimeter of Triangle = %.2f\n",s) ("\n The Perimeter of the Triangle = %.2f\n", Perimeter) ("\n Enter the Three sides of triangle: ") Īrea = Math.sqrt(s*(s-side1)*(s-side2)*(s-side3)) Java Program to find Area of Triangle when three sides are given The below example illustrates the implementation of the above algorithm. Then, calculate the area using the formula.First, calculate the semi-perimeter of the triangle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |