/*
Enter a point's x- and y-coordinates: 100.5 25.5
The point is in the triangle.
Enter a point's x- and y-coordinates: 100.5 50.5
The point is not in the triangle.
*/
import java.util.Scanner;
public class PointInRightAngleTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a point's x- and y-coordinates: ");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x = 200, y = 100;
double maxDistance = Math.sqrt(x * x + y * y) / 2;
double distance = Math.sqrt(x1 * x1 + y1 * y1);
if (distance <= maxDistance)
System.out.println("The point is in the triangle.");
else
System.out.println("The point is not in the triangle.");
}
}
Introduction to Java Programming编程题3.27<判断点是否在三角形内>
最新推荐文章于 2017-03-17 08:07:31 发布
本文介绍了一个简单的Java程序,该程序通过输入点的坐标来判断该点是否位于一个特定的直角三角形内部。三角形的直角位于坐标原点,程序计算点到原点的距离并与三角形的最大距离进行比较。
958

被折叠的 条评论
为什么被折叠?



