Java Function that prints perimeter and area of right triangle.

//Java Function that prints perimeter and area of right triangle.



import java.util.Scanner;
import java.lang.Math;

public class Program 
{   
    	public static void main( String[] args ) 
    	{
		Scanner reader = new Scanner(System.in);
		float a, b, c, peri,ar,s;
		System.out.print("\nPlease Enter three sides of triangle\n");
		a = reader.nextInt();
		b = reader.nextInt();
		c = reader.nextInt();
		peri=triangle_perimeter(a,b,c);
		ar=triangle_area(a,b,c);
		System.out.print("\nPerimeter of Traiangle = "+ peri +"\n");
		System.out.print("\nArea of triangle = "+ ar +"\n");
	}
	public static float triangle_area(float a,float b,float c)
	{
		float s,area;
		s = (a+b+c)/2;
		area = (float)Math.sqrt(s*(s-a)*(s-b)*(s-c));
		return area;
	}
	public static float triangle_perimeter(float a,float b,float c)
	{
	    	float area,perimeter;
	    	perimeter = a+b+c;
	    	return perimeter;
     	}
}

Output :
Please Enter three sides of triangle
2
3
4

Perimeter of Traiangle = 9.00

Area of triangle = 2.90



Leave a comment