Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Homework2;
- import java.util.Scanner;
- public class TriangleArea {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter Ax: ");
- int Ax = sc.nextInt();
- System.out.print("Enter Ay: ");
- int Ay = sc.nextInt();
- System.out.print("Enter Bx: ");
- int Bx = sc.nextInt();
- System.out.print("Enter By: ");
- int By = sc.nextInt();
- System.out.print("Enter Cx: ");
- int Cx = sc.nextInt();
- System.out.print("Enter Cy: ");
- int Cy = sc.nextInt();
- double area = Math.abs( (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay-By) ) / 2.0);
- if (area == 0) {
- System.out.println("0");
- }
- else {
- System.out.println("The area of this triangle is: " + (int)area);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement