Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*2.Write a program that enters 3 points in the plane (as integer x and y coordinates),
- calculates and prints the area of the triangle composed by these 3 points.
- Round the result to a whole number. In case the three points do not form a triangle,
- print "0" as result.*/
- /*Tests:
- -5 10 25 30 60 15 ans: 575
- 53 18 56 23 24 27 ans: 86
- 1 1 2 2 3 3 ans: 0*/
- import java.util.Scanner;
- public class TriangleArea {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the coords of the triangle!");
- double aX =input.nextDouble();
- double aY =input.nextDouble();
- double bX =input.nextDouble();
- double bY =input.nextDouble();
- double cX =input.nextDouble();
- double cY =input.nextDouble();
- int area = (int)(Math.abs(((aX*(bY-cY))+(bX*(cY-aY))+(cX*(aY-bY)))/2));
- System.out.println("The triangle area is = " + area);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement