Answers for "area of a triangle in Java"

1

Java program to find area of triangle

import java.util.Scanner;
public class FindAreaOfTriangle
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter width of triangle: ");
      double base = sc.nextDouble();
      System.out.println("Please enter height of triangle: ");
      double height = sc.nextDouble();
      // formula area of triangle = (width * height) / 2
      double area = (base * height) / 2;
      System.out.println("Area of triangle is: " + area);
      sc.close();
   }
}
Posted by: Guest on February-18-2021
0

area of right angle triangle in java

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // area of right angled triangle

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter base length: ");
        float base = scanner.nextFloat();

        System.out.print("Enter perpendicular length: ");
        float perpendicular = scanner.nextFloat();

        float area = 0.5f * base * perpendicular;

        System.out.println("The area is: " + area);
    }
}
Posted by: Guest on June-27-2021

Code answers related to "area of a triangle in Java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language