java输入a,b,c,3个点的三维坐标,判断三个点能否形成三角形的代码
时间: 2024-05-27 11:10:40 浏览: 19
以下是 java 代码实现:
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一个点的坐标 (a, b, c):");
int a1 = input.nextInt();
int b1 = input.nextInt();
int c1 = input.nextInt();
System.out.print("请输入第二个点的坐标 (a, b, c):");
int a2 = input.nextInt();
int b2 = input.nextInt();
int c2 = input.nextInt();
System.out.print("请输入第三个点的坐标 (a, b, c):");
int a3 = input.nextInt();
int b3 = input.nextInt();
int c3 = input.nextInt();
// 判断三个点能否形成三角形
if ((a1 == a2 && b1 == b2 && c1 == c2) ||
(a1 == a3 && b1 == b3 && c1 == c3) ||
(a2 == a3 && b2 == b3 && c2 == c3)) {
System.out.println("三个点不能形成三角形!");
} else {
double ab = Math.sqrt(Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) + Math.pow(c1 - c2, 2));
double ac = Math.sqrt(Math.pow(a1 - a3, 2) + Math.pow(b1 - b3, 2) + Math.pow(c1 - c3, 2));
double bc = Math.sqrt(Math.pow(a2 - a3, 2) + Math.pow(b2 - b3, 2) + Math.pow(c2 - c3, 2));
if (ab + ac > bc && ab + bc > ac && ac + bc > ab) {
System.out.println("三个点能够形成三角形!");
} else {
System.out.println("三个点不能形成三角形!");
}
}
}
}
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)