您的位置:首页 > 其它

编写一个控制台程序,能够处理以下命令,利用args

2012-01-19 16:35 351 查看
1、用户输入 *.exe x + y(x和y是整数,输出 x + y的结果)。

2、用户输入 *.exe x – y(x和y是整数,输出 x - y的结果)。

3、用户输入 *.exe x / y(x和y是整数,输出 x / y的结果)。

4、用户输入 *.exe x * y(x和y是整数,输出 x * y的结果)。

5、用户输入 *.exe –h则显示帮助。

class Program
{
static void Main(string[] args)
{
string a = args[0];

try
{
if (a == "-h")
{
Console.WriteLine("This is Help Document !");
}
else
{
string b = args[1];
string c = args[2];

int ai = int.Parse(a);
int ci = int.Parse(c);

if (b == "+")
{
Console.WriteLine("{0} + {1} = {2}", ai, ci, ai + ci);
}
else if (b == "-")
{
Console.WriteLine("{0} - {1} = {2}", ai, ci, ai - ci);
}
else if (b == "*")
{
Console.WriteLine("{0} * {1} = {2}", ai, ci, ai * ci);
}
else if (b == "/")
{
Console.WriteLine("{0} / {1} = {2}", ai, ci, ai / ci);
}
else
{
Console.WriteLine("Invaliable b!");
}
}
}
catch (Exception)
{
Console.WriteLine("Invaliable a !");
}
Console.ReadKey();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐