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.Call the method and return the calculated area.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 to calculate area and circumference of Circle In this program, radius value is specified in the program and we are calculating the area and circumference using the above mentioned formulas. 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.Then we will create another class in which we will create a main method. And the method Area and Perimeter to calculate the Area and Perimeter of Rectangle. Use Heron's Formula to Calculate the area of the triangle. Approach : First, we will create a class called Rectangle in which we will define the variable length and breadth.Ask the user to initialize these variables.Declare variables to store the triangle sides.Create an instance of the Scanner class. In this program, we will see how to calculate the area of the triangle when the three sides are given using heron's formula. Program 1: Java Program to find Area of a Triangle when Three Sides are Given Let us look at the examples for a better understanding. Here s = semi perimeter and a, b, c are the three sides of a triangle. But before moving forward, if you are not familiar with the concept of data types in java then do check the article on Datatypes in Java.Īrea of a Triangle = (s*(s-a)*(s-b)*(s-c))^½ Heron’s formula is used to find the area of a triangle when we know the length of all its sides. This can be done by using heron's formula. this tutorial, we will see how to calculate the area of the triangle when the three sides are given. In this values for length and breadth of rectangle will be taken by the user. ("Area of rectangle :"+area) Īrea of rectangle : 8.4 Method-2: Java Program to Find Area and Perimeter of Rectangle By using dynamic values Let’s see the program to understand it more clearly. In this values for length and breadth of rectangle are already taken. Method-1: Java Program to Find Area and Perimeter of Rectangle By using static values Try practicing the core java programs with the help of the Java basic programs list available. If you are new to Java and want to learn the java coding skills too fast. Then area of rectangle => perimeter = (length * breadth) => area = 18 Example- To find Perimeter of Rectangle Then area of rectangle => area = 2 * (length + breadth) (smaller side of rectangle)Įxample: Example- To find Area of Rectangle
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |