WAP in java to calculate area of eqilateral,isosceles & scalene triangle according to users choice?

Опубликовано: 17 Июнь 2026
на канале: PROGRAM.. DEVIL
17
5

🔥 Welcome to PROGRAM DEVIL 🔥

In this video, we’ll write a Java program that calculates the area of Equilateral, Isosceles, and Scalene triangles based on the user’s choice.
Whether you're a beginner or brushing up on your Java, this program is a great practice for using conditional statements, mathematical formulas, and scanner input!

💻 Program Description:
✔️ Learn how to calculate the area of an Equilateral Triangle
✔️ Learn how to calculate the area of an Isosceles Triangle
✔️ Learn how to calculate the area of a Scalene Triangle
All calculations are done using simple Java logic — explained step by step!

📌 Java Source Code (With Comments)

```java
import java.util.*; // Importing Scanner class for input
public class areatriangle // Declaring the class
{
public static void main(String args[]) // Main method
{
Scanner sc = new Scanner(System.in); // Creating Scanner object for user input
int choice;
double a, b, c, area, s;

// Displaying the choice menu to the user
System.out.println("Enter the choice");
System.out.println("Enter 1 for Area of Equilateral Triangle");
System.out.println("Enter 2 for Area of Isosceles Triangle");
System.out.println("Enter 3 for Area of Scalene Triangle");
choice = sc.nextInt(); // Taking user's choice

switch (choice) {
case 1: // If choice is 1, calculate Equilateral Triangle area
System.out.println("Enter the side of an equilateral triangle");
a = sc.nextInt(); // Input side length
area = (Math.sqrt(3) / 4) * a * a; // Area formula
System.out.println("Area of an EQUILATERAL TRIANGLE: " + area);
break;

case 2: // If choice is 2, calculate Isosceles Triangle area
System.out.println("Enter the base of an isosceles triangle");
b = sc.nextInt(); // Input base
System.out.println("Enter the side of an isosceles triangle");
a = sc.nextInt(); // Input side
area = b / 4 * Math.sqrt((4 * a * a) - (b * b)); // Area formula
System.out.println("Area of an ISOSCELES TRIANGLE: " + area);
break;

case 3: // If choice is 3, calculate Scalene Triangle area
System.out.println("Enter all the three sides of a scalene triangle");
a = sc.nextInt(); // Side 1
b = sc.nextInt(); // Side 2
c = sc.nextInt(); // Side 3
s = (a + b + c) / 2; // Semi-perimeter
area = Math.sqrt(s * (s - a) * (s - b) * (s - c)); // Heron's formula
System.out.println("Area of a SCALENE TRIANGLE: " + area);
break;

default: // Invalid choice handling
System.out.println("Wrong Choice");
break;
}
}
}
```

📲 Join our community!
👉 Telegram: [https://t.me/+iQTEQxvTmq43MGQ1](https://t.me/+iQTEQxvTmq43MGQ1)
👉 Instagram (Threads): [https://www.threads.net/@program_devi...](https://www.threads.net/@program_devi...)

📧 For Queries: [email protected]

---

👍 LIKE | 💬 COMMENT | 🔔 SUBSCRIBE
Stay tuned for more Java, C++, Python, and tech-related programming content!

#JavaProgram #ProgramDevil #TriangleArea #JavaTutorial #CodingForBeginners #JavaProjects #LearnProgramming #TelegramCommunity #ProgramDevilFamily