using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2{ class Program { static void Main(string[] args) { double z = 0; double x = Convert.ToDouble(Console.ReadLine()); string u = Console.ReadLine(); double y = Convert.ToDouble(Console.ReadLine()); switch (u) { case "+": z = x + y; Console.WriteLine("{}{}{}={}",x,u,y,z); break; case "/": z = x / y; Console.WriteLine("{}{}{}={}",x,u,y,z); break; case "-": z = x - y; Console.WriteLine("{}{}{}={}",x,u,y,z); break; case "*": z = x * y; Console.WriteLine("{}{}{}={}",x,u,y,z); break; case "%": z = x % y; Console.WriteLine("{}{}{}={}",x,u,y,z); break; default: Console.WriteLine("您输入的运算符号有问题"); break; } Console.ReadLine(); } }}
1 回答
习惯受伤
TA贡献885条经验 获得超1144个赞
这是段c#代码,其中很明显的格式化输出格式有错误,这一行:
Console.WriteLine("{}{}{}={}",x,u,y,z);
正确的应为:
Console.WriteLine("{0}{1}{2}={3}",x,u,y,z);
大括号和大括号中间的数字会被后边的参数,依次替换。
添加回答
举报
0/150
提交
取消