Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.ukr.shyevhen;
- import java.util.Scanner;
- public class HomeWorkL2E2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int x0;
- int y0;
- int x1 = 0;
- int y1 = 0;
- int x2 = 4;
- int y2 = 4;
- int x3 = 6;
- int y3 = 1;
- int a;
- int b;
- int c;
- System.out.print("Enter coordinate x: ");
- x0 = sc.nextInt();
- System.out.print("Enter coordinate y: ");
- y0 = sc.nextInt();
- a = (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0);
- b = (x2 - x0) * (y3 - y2) - (x3 - x2) * (y2 - y0);
- c = (x3 - x0) * (y1 - y3) - (x1 - x3) * (y3 - y0);
- if ((a <= 0 && b <= 0 && c <= 0) || (a >= 0 && b >= 0 && c >= 0)) {
- System.out.println("This point in the triangle.");
- } else {
- System.out.println("This point isn't in the triangle.");
- }
- }
- }
Add Comment
Please, Sign In to add comment