public class PointTest {
public static void main(String[] args) {
Point p1 = new Point(1,2);
Point p2 = new Point(1,20);
java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
double d = p2.distance(p1);
System.out.println(df.format(d));
}
}
本文提供了一个简单的Java程序示例,展示了如何使用自定义的Point类来计算两个点之间的距离,并通过DecimalFormat类对结果进行格式化输出。
29

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



