回顾挑战 #1
Coddy Java 类和对象基础 课程的第 12 课,共 12 课。
挑战
简单给定一段包含 Point 类的代码。
你的任务是在 main 方法中实现程序,从输入中获取两个点,并计算它们之间的距离。
输入顺序如下:
x1
y1
x2
y2
亲手试试
import java.lang.Math;
import java.util.Scanner;
class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public double distFrom(Point otherPoint) {
return Math.sqrt(Math.pow(this.x - otherPoint.x, 2) + Math.pow(this.y - otherPoint.y, 2))
}
}
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 在这里编写代码
}
}Java 类和对象基础中的所有课
自己练习: Java 在线编译器