KnowledgeBoat Logo

Computer Applications

A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not.
For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.

Java

Java Conditional Stmts

124 Likes

Answer

import java.util.Scanner;

public class KboatEquableTriangle
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.println("Please enter the 3 sides of the triangle.");
        
        System.out.print("Enter the first side: ");
        double a = in.nextDouble();
        
        System.out.print("Enter the second side: ");
        double b = in.nextDouble();
        
        System.out.print("Enter the third side: ");
        double c = in.nextDouble();
        
        double p = a + b + c;
        double s = p / 2;
        double area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
        
        if (area == p)
            System.out.println("Entered triangle is equable.");
        else 
            System.out.println("Entered triangle is not equable.");
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not. For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.

Answered By

48 Likes


Related Questions