用java生成一个程序,设置圆心为(0,0),输入x,y轴坐标,该圆心半径为10,判断是在圈内还是圈外
时间: 2024-05-03 17:21:13 浏览: 13
下面是一个示例代码:
```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,则该点在圆内;否则在圆外。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)