C# 将Double转换为Bool
我试图找出给定的点是否在一个圆内,这是我目前的解决方案C# 将Double转换为Bool,c#,geometry,C#,Geometry,我试图找出给定的点是否在一个圆内,这是我目前的解决方案 using System; //Write an expression that checks if given point (x, y) is inside a circle K({0, 0}, 2). class Program { static void Main() { Console.Write("Enter x: "); double x = double.Parse(Cons
using System;
//Write an expression that checks if given point (x, y) is inside a circle K({0, 0}, 2).
class Program
{
static void Main()
{
Console.Write("Enter x: ");
double x = double.Parse(Console.ReadLine());
Console.Write("Enter y: ");
double y = double.Parse(Console.ReadLine());
bool insideCircle = (double)Math.Sqrt((x * x) + (y + y) <= 2);
}
}
使用系统;
//编写一个表达式,检查给定点(x,y)是否在圆K({0,0},2)内。
班级计划
{
静态void Main()
{
Console.Write(“输入x:”);
double x=double.Parse(Console.ReadLine());
控制台。写入(“输入y:”;
double y=double.Parse(Console.ReadLine());
bool insideCircle=(double)Math.Sqrt((x*x)+(y+y)你应该移动你应该移动你的括号放错地方了
bool insideCircle = Math.Sqrt((x * x) + (y + y)) <= 2.0;
bool insideCircle=Math.Sqrt((x*x)+(y+y))括号放错地方了
bool insideCircle = Math.Sqrt((x * x) + (y + y)) <= 2.0;
bool insideCircle=Math.Sqrt((x*x)+(y+y))我相信你的意思是:
class Program
{
static void Main()
{
Console.Write("Enter x: ");
double x = double.Parse(Console.ReadLine());
Console.Write("Enter y: ");
double y = double.Parse(Console.ReadLine());
// <= 2 is outside the brackets, not inside
bool insideCircle = Math.Sqrt((x * x) + (y + y)) <= 2;
}
}
类程序
{
静态void Main()
{
Console.Write(“输入x:”);
double x=double.Parse(Console.ReadLine());
控制台。写入(“输入y:”;
double y=double.Parse(Console.ReadLine());
//我相信你的意思是:
class Program
{
static void Main()
{
Console.Write("Enter x: ");
double x = double.Parse(Console.ReadLine());
Console.Write("Enter y: ");
double y = double.Parse(Console.ReadLine());
// <= 2 is outside the brackets, not inside
bool insideCircle = Math.Sqrt((x * x) + (y + y)) <= 2;
}
}
类程序
{
静态void Main()
{
Console.Write(“输入x:”);
double x=double.Parse(Console.ReadLine());
控制台。写入(“输入y:”;
double y=double.Parse(Console.ReadLine());
//double-insideCircle
而不是bool-insideCircle
。您认为如何将Math.Sqrt
部分转换为double
,它应该返回bool
?您希望通过右侧操作得到bool
什么?使用Math.Sqrt((3*5)+(3+5))我认为你在两个方面都有这个错误。作为一个学习练习,用小步写出它。为什么要将double
转换为bool
?为什么不只使用if
语句?(例如,if(范围内的double)then bool=true)除了提供的答案外,距离计算中的y+y
应该是y*y
double-insidercle
而不是bool-insidercle
。您认为如何将Math.Sqrt
部分转换为double
,它应该返回bool
?您想获得什么样的结果你的右侧操作是一个bool
?使用Math.Sqrt((3*5)+(3+5))我认为你在两个方向上都有这个错误。作为一个学习练习,用较小的步骤写出来。为什么要将double
转换为bool
?为什么不直接使用if
语句?(例如if(范围内的double)然后bool=true)除了提供的答案外,距离计算中的y+y
应该是y*y
谢谢你解决了它!如果这是一个愚蠢的问题,我很抱歉。我对编程非常陌生。谢谢你解决了它!如果这是一个愚蠢的问题,我很抱歉。我对编程非常陌生。