Win11 搭建FTP
时间: 2024-06-04 14:10:40 浏览: 104
在windows上搭建FTP服务
import java.util.Scanner;
public class ShortestDistance {
public static void main(String[] args) {
//读取用户输入的点的坐标
double[][] points = getArray(6, 3);
//计算最短距离的两个点及返回最短距离
double[][] shortDistancePoint = new double[2][3];
double shortestDistance = getShortestDistance(points, shortDistancePoint);
//打印输出最短距离的两个点
printShortestDistance(shortDistancePoint);
//打印输出最短距离
System.out.println("最短距离为:" + shortestDistance);
}
//读取用户输入的点的坐标
public static double[][] getArray(int n1, int n2) {
Scanner input = new Scanner(System.in);
double[][] array = new double[n1][n2];
for (int i = 0; i < n1; i++) {
System.out.print("请输入第" + (i + 1) + "个点的坐标(x, y, z):");
array[i][0] = input.nextDouble();
array[i][1] = input.nextDouble();
array[i][2] = input.nextDouble();
}
return array;
}
//计算两个点之间的距离
public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2));
}
//计算最短距离的两个点及返回最短距离
public static double getShortestDistance(double[][] points, double[][] shortDistancePoint) {
double shortestDistance = Double.MAX_VALUE;
for (int i = 0; i < points.length; i++) {
for (int j = i + 1; j < points.length; j++) {
double distance = distance(points[i][0], points[i][1], points[i][2], points[j][0], points[j][1], points[j][2]);
if (distance < shortestDistance) {
shortestDistance = distance;
shortDistancePoint[0] = points[i];
shortDistancePoint[1] = points[j];
}
}
}
return shortestDistance;
}
//打印输出最短距离的两个点
public static void printShortestDistance(double[][] shortDistancePoint) {
System.out.println("最短距离的两个点为:");
for (int i = 0; i < 2; i++) {
System.out.println("(" + shortDistancePoint[i][0] + ", " + shortDistancePoint[i][1] + ", " + shortDistancePoint[i][2] + ")");
}
}
}
阅读全文