作业帮 > 综合 > 作业

函数Y的表达式如下,输入一个X的值,求Y的值 x x

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 11:38:26
函数Y的表达式如下,输入一个X的值,求Y的值 x x
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int x;
try
{
x = Convert.ToInt32(str);
}
catch (FormatException e)
{
return;
}
float y = Method(x);
Console.WriteLine("y = " + y.ToString());
Console.ReadLine();
}
static float Method(int x)
{
float y = 0;
if (x < 0)
{
y = x;
}
else if (0 < x && x