用ASP.NET编写一个计算器(能实现加减乘除的)
答案:1 悬赏:40 手机版
解决时间 2021-04-07 08:30
- 提问者网友:爱了却不能说
- 2021-04-06 20:35
用ASP.NET编写一个计算器(能实现加减乘除的)
最佳答案
- 五星知识达人网友:怙棘
- 2021-04-06 21:49
贴个最简单的吧:
Operation类:
class Operation
{
public static double GetResult(double numberA, double numberB, string operate)
{
double result = 0d;
switch (operate)
{
case "+":
result = numberA + numberB;
break;
case "-":
result = numberA - numberB;
break;
case "*":
result = numberA * numberB;
break;
case "/":
result = numberA / numberB;
break;
}
return result;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.WriteLine("请输入运算符号(+ - * /)");
string strOperate = Console.ReadLine();
Console.WriteLine("请输入数字B:");
string strNumberB = Console.ReadLine();
string strResult;
strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB), strOperate));
Console.WriteLine("结果是:" + strResult);
Console.ReadLine();
}
}
Operation类:
class Operation
{
public static double GetResult(double numberA, double numberB, string operate)
{
double result = 0d;
switch (operate)
{
case "+":
result = numberA + numberB;
break;
case "-":
result = numberA - numberB;
break;
case "*":
result = numberA * numberB;
break;
case "/":
result = numberA / numberB;
break;
}
return result;
}
}
Program.cs:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入数字A:");
string strNumberA = Console.ReadLine();
Console.WriteLine("请输入运算符号(+ - * /)");
string strOperate = Console.ReadLine();
Console.WriteLine("请输入数字B:");
string strNumberB = Console.ReadLine();
string strResult;
strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB), strOperate));
Console.WriteLine("结果是:" + strResult);
Console.ReadLine();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯