简单的C#控制台程序哦

GonnaWon 2009-01-09 12:40:51
编写程序,求函数x<0时y=-1;x=0时y=0;x>0时y=1 的值
...全文
125 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
caorenlong 2009-01-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 much0726 的回复:]
这个不难吧?有什么特别的要求吗?

C# code
if(x<0)
{
y=-1;
}
else if(x=0)
{
y=0;
}
else
{
y=1;
}
[/Quote]
正解啊.
可以再加一个输入 X的值
还有一个输出 y的值.
Console.WriteLine("来个数:");
string x=Console.ReadLine();
Console.WriteLine("y的值为{0}:",x);
much0726 2009-01-09
  • 打赏
  • 举报
回复
这个不难吧?有什么特别的要求吗?

if(x<0)
{
y=-1;
}
else if(x=0)
{
y=0;
}
else
{
y=1;
}
woloveyu 2009-01-09
  • 打赏
  • 举报
回复
好好。。。
justxd 2009-01-09
  • 打赏
  • 举报
回复
o
码YouMe 2009-01-09
  • 打赏
  • 举报
回复
飘过。。。
睡神在睡觉 2009-01-09
  • 打赏
  • 举报
回复
哎……什么问题都有……这。。。哎……
jxxx2967 2009-01-09
  • 打赏
  • 举报
回复
哈哈
破碎的脸 2009-01-09
  • 打赏
  • 举报
回复
class Program
{
static void Main(string[] args)
{
loop1:
//编写程序,求函数x <0时y=-1;x=0时y=0;x>0时y=1 的值
int i = int.Parse(Console.ReadLine());
Console.WriteLine(i == 0 ? 0 : i / Math.Abs(i)); goto loop1;
}
}

OK,进水完成。。。。只用了一行代码。。。。
破碎的脸 2009-01-09
  • 打赏
  • 举报
回复
class Program
{
static void Main(string[] args)
{
loop1:
//编写程序,求函数x <0时y=-1;x=0时y=0;x>0时y=1 的值
int i = int.Parse(Console.ReadLine());
Console.WriteLine(i == 0 ? 0 : i / Math.Abs(i));
goto loop1;
}
}

OK,进水完成。。。。
破碎的脸 2009-01-09
  • 打赏
  • 举报
回复
static void Main(string[] args)
{
loop1:
//编写程序,求函数x <0时y=-1;x=0时y=0;x>0时y=1 的值
int i = int.Parse(Console.ReadLine());
try
{
Console.WriteLine(i / Math.Abs(i));
}
catch
{
Console.WriteLine("0");
}
goto loop1;
}

脑子进水的写法。。。。。为我的想象力鼓掌吧!
Hertz_liu 2009-01-09
  • 打赏
  • 举报
回复

static void Main(string[] args)
{
Console.Write("请输入X的值:");
string data = Console.ReadLine();
bool flag = IsNumber(data);
if (flag == true)
{
int intData = Convert.ToInt32(data);
int Y;
if (intData > 0)
{
Y = 1;
}
else
{
if (intData == 0)
{
Y = 0;
}
else
{
Y = -1;
}
}
Console.WriteLine("根据您输入的X值,得出Y的值为:"+Y.ToString());
}
else
{
Console.WriteLine("请输入整数");
}
Console.ReadKey();
}

static bool IsNumber(string data)
{
Regex r = new Regex("^[-]{0,1}\\d+$");//这个正则只验证整数,根据需要,自己写正则
Match m = r.Match(data);
if (m.Success)
{
return true;
}
return false;
}

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧