用java生成一个程序,设置圆心为(0,0),输入x,y轴坐标,该圆心半径为10,判断是在圈内还是圈外
时间: 2024-05-03 07:21:13 浏览: 79
TestCircle.rar_java小程序_判断是否为圆
下面是一个示例代码:
```java
import java.util.Scanner;
public class CircleTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the x-coordinate: ");
double x = input.nextDouble();
System.out.print("Enter the y-coordinate: ");
double y = input.nextDouble();
double distance = Math.sqrt(x * x + y * y);
if (distance <= 10) {
System.out.println("The point (" + x + ", " + y + ") is inside the circle.");
} else {
System.out.println("The point (" + x + ", " + y + ") is outside the circle.");
}
}
}
```
这个程序首先让用户输入x和y坐标,然后通过勾股定理计算出该点到圆心的距离distance。如果distance小于等于10,则该点在圆内;否则在圆外。
阅读全文