首页上一页 1 下一页尾页 1 条记录 1/1页
控制台应用程序(计算器)
发表在新手报到
2021-12-23
是否精华
是
否
版块置顶:
是
否
using System; namespace Start { class StartOne { static void Main(String[] args) { Console.WriteLine("------------------------------------------"); Console.WriteLine(" 1. 加法运算"); Console.WriteLine("| |"); Console.WriteLine(" 2. 减法运算"); Console.WriteLine("| |"); Console.WriteLine(" 3. 乘法运算"); Console.WriteLine("| |"); Console.WriteLine(" 4. 除法运算"); Console.WriteLine("| |"); Console.WriteLine(" 5. 退 出"); Console.WriteLine(); Console.WriteLine("------------------------------------------"); Console.WriteLine("请输入想使用的功能:"); Function function = new Function(); function.functionNum = Convert.ToInt32(Console.ReadLine()); Operation operation = new Operation(); Console.Write("请输入第一个数:"); operation.AddNum1 = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入第二个数:"); operation.AddNum2 = Convert.ToInt32(Console.ReadLine()); if (function.functionNum == 1) operation.Add(); else if (function.functionNum == 2) operation.Subtraction(); else if (function.functionNum == 3) operation.Multiplication(); else if (function.functionNum == 4) operation.Division(); else Console.WriteLine("感谢您的使用,即将退出!!!"); operation.Result(); Console.WriteLine(function.result); Console.ReadKey(); } } class Function { public int functionNum; public string result="结果为:"; } class Operation { public int AddNum1, AddNum2, AddNum3; public int Add() { AddNum3 = AddNum1 + AddNum2; return AddNum3; } public void Subtraction() { AddNum3 = AddNum1 - AddNum2; } public void Multiplication() { AddNum3 = AddNum1 * AddNum2; } public void Division() { double DAddNum1 = Convert.ToDouble(AddNum1); double DAddNum2 = Convert.ToDouble(AddNum2); double DAddNum3 = Convert.ToDouble(AddNum3); DAddNum3 = DAddNum1 / DAddNum2; } public string Result() { Function function = new Function(); if (function.functionNum == 1) function.result = "结果为:" + AddNum3; return function.result; } } } 为啥在运行的时候会抛出异常{System.StackOverflowException:“Exception_WasThrown”}