/*
Enter a point with two coordinates: 4 5
Point (4.0, 5.0) is in the circle.
Enter a point with two coordinates: 9 9
Point (9.0, 9.0) is not in the circle.
*/
import java.util.Scanner;
public class PointInACircle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double x1, y1;
x1 = y1 = 0;
System.out.print("Enter a point with two coordinates: ");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
if (distance <= 10)
System.out.println("Point (" + x2 + ", " + y2 + ")" + " is in the circle.");
else
System.out.println("Point (" + x2 + ", " + y2 + ")" + " is not in the circle.");
}
}
Introduction to Java Programming编程题3.22<判断点是否在圆内>
最新推荐文章于 2025-01-09 17:07:48 发布
本文介绍了一个简单的Java程序,该程序通过输入一个二维坐标来判断该点是否位于以原点为中心、半径为10的圆内。程序首先计算点到原点的距离,然后根据距离与圆半径的关系判断点是否在圆内。
1505

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



