Menu
CoddyTech

复习挑战 #1

Coddy C# 类和对象基础 课程的第 12 课,共 12 课。

challenge icon

挑战

简单

给你一段包含 Point 类的代码。

你的任务是在 main 方法中实现程序,从输入中获取两个点,并计算它们之间的距离。

输入顺序如下:

x1

y1

x2

y2

亲手试试

using System;

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 Program {
    public static void Main(string[] args) {
        // 在这里编写代码
    }
}

C# 类和对象基础中的所有课

自己练习: C# 在线编译器