In order to compute the area of the triangle, two parameters are needed namely base and height. For this simply the variables are assigned with zeros. The area of the triangle can be computed by using the same third-grade mathematics formula.
Area = 1/2(Base * Height)
Input: (1,3) (5,-2) (-3,6)
Output: Area of triangle: 4
Processing: 1/2 (|3*3 Determinant|)
Determinant: In linear algebra, the determinant is a scalar value that can be computed from the elements of a square matrix and encodes certain properties of the linear transformation described by the matrix. Matrix is simply a two–dimensional array. Arrays are linear data structures in which elements are stored in a contiguous manner.
- Co-ordinates are asked from the user one by one
- 1 is assigned to the third column in the matrix
- Math library is imported for computation of numbers using formula over input elements
- The absolute method is applied over the value stored in a variable
datatype typename = Math.abs(value)
Return type: A value on the number line lying on the right side of 0
Math is a library in java for computing calculations over numbers which consist of function absolute whose use is to covert value being positive or negative to a positive value. Here it is used as a practically thinking area that can never be negative in real space. If something is occupying space it will definitely occupy space and will have the area.
Implementation: Java program to compute the area of a triangle
Area of triangle: 2.0
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.