Computer Science, asked by samridhisethi, 11 months ago

write a program to calculate the area of triangle​

Answers

Answered by sulagnasg77
2

import java.util.Scanner;

class AreaTriangleDemo {

  public static void main(String args[]) {    

     Scanner scanner = new Scanner(System.in);

     System.out.println("Enter the width of the Triangle:");

     double base = scanner.nextDouble();

     System.out.println("Enter the height of the Triangle:");

     double height = scanner.nextDouble();

     //Area = (width*height)/2

     double area = (base* height)/2;

     System.out.println("Area of Triangle is: " + area);      

  }

}

output :

Enter the width of the Triangle:

2

Enter the height of the Triangle:

2

Area of Triangle is: 2.0

Answered by Shivu516
0

Hope it helps ^_^

This program asks the measure of sides as the input instead of base and height.

This program is in Java

_____________________________________

import java.util.Scanner;

public class Area_Of_Triangle{

   public static void main(String[] args){

       Scanner sc = new Scanner(System.in);

       double a1, a2, a3, s, area;

       System.out.print("Enter the first angle: ");

       a1 = sc.nextDouble();

       System.out.print("Enter the second angle: ");

       a2 = sc.nextDouble();

       System.out.print("Enter the third angle: ");

       a3 = sc.nextDouble();

       boolean truth = (a1+a2) > a3 && (a1 + a3) > a2 && (a2 + a3) > a1;

       if (truth == true){

       s = (a1 + a2 + a3)/2;

       area = Math.sqrt(s * (s - a1) * (s - a2) * (s - a3));

       System.out.println("Area of this triangle: " + area + " sq.unit");

       }

       else if (truth == false){

       System.out.println("These sides cannot form a triangle *_*");

       }

   }

}

_____________________________________

Outputs:

(i)

Enter the first angle: 52

Enter the second angle: 48

Enter the third angle: 20

Area of this triangle: 480.0 sq.unit

(ii)

Enter the first angle: 5

Enter the second angle: 2

Enter the third angle: 3

These sides cannot form a triangle *_*

Attachments:
Similar questions