首先switch没有break,其次Sum1的是Sum类的一个实例方法,应该实例化Sum,然后调用Sum1方法- //用面向对象做计算器
- // 1.输入数字+符号
- Console.WriteLine("请您输入数字1");
- int numBer1 =Convert.ToInt32( Console.ReadLine());
- Console.WriteLine("请您输入字符串");
- string char1 = Console.ReadLine();
- Console.WriteLine("请您输入数字2");
- int numBer2 =Convert.ToInt32( Console.ReadLine());
- int output = 0;
- // 2.调用
- switch (char1)
- {
- case "+": output = new Sum().Sum1(numBer1, numBer2);break; //这Sum1 调用不了
- case "-":break;
- case "*":break;
- case"/":break;
- default: Console.WriteLine("输入错误");break;
- }
- Console.WriteLine("{0}{1}{2}={3}", numBer1, char1, numBer2, output);
- Console.ReadKey(true);
复制代码 |