c# 编写一个控制台应用程序,计算两个点之间的直线距离
这个是我的代码,可是在静态方法里报错,说不可访问受保护级别限制。请问如何改正?usingSystem;usingSystem.Collections.Generic;us...
这个是我的代码,可是在静态方法里报错,说不可访问受保护级别限制。请问如何改正?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 计算两点间距
{
public class Point {
double x;
double y;
public Point() {
x = 0;
y = 0;
}
public Point(double a, double b) {
x = a;
y = b;
}
}
class Program
{
static void Main(string[] args)
{
double a,b,c,d=0;
Console.WriteLine("请输入第一个点的坐标:");
a = Double.Parse(Console.ReadLine());
b = Double.Parse(Console.ReadLine());
Console.WriteLine("请输入第二个点的坐标:");
c = Double.Parse(Console.ReadLine());
d = Double.Parse(Console.ReadLine());
Point test1 = new Point(a,b);
Point test2 = new Point(c,d);
Console.ReadLine();
}
public static void Calculate(Point a, Point b)
{
double length;
double lengthF;
double xC;
double yC;
xC = a.x - b.x;
yC = a.y - b.y;
lengthF = Math.Pow(xC, 2.0) + Math.Pow(yC, 2.0);
length = Math.Sqrt(lengthF);
Console.WriteLine(length);
Console.ReadLine();
}
}
} 展开
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 计算两点间距
{
public class Point {
double x;
double y;
public Point() {
x = 0;
y = 0;
}
public Point(double a, double b) {
x = a;
y = b;
}
}
class Program
{
static void Main(string[] args)
{
double a,b,c,d=0;
Console.WriteLine("请输入第一个点的坐标:");
a = Double.Parse(Console.ReadLine());
b = Double.Parse(Console.ReadLine());
Console.WriteLine("请输入第二个点的坐标:");
c = Double.Parse(Console.ReadLine());
d = Double.Parse(Console.ReadLine());
Point test1 = new Point(a,b);
Point test2 = new Point(c,d);
Console.ReadLine();
}
public static void Calculate(Point a, Point b)
{
double length;
double lengthF;
double xC;
double yC;
xC = a.x - b.x;
yC = a.y - b.y;
lengthF = Math.Pow(xC, 2.0) + Math.Pow(yC, 2.0);
length = Math.Sqrt(lengthF);
Console.WriteLine(length);
Console.ReadLine();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询