namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input:");
//string x = Console.ReadLine();
int x, y;
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} + {0} = {0}", x, y, x + y);
Console.ReadKey();
}
}
}c#函数,输入两个数字x,y,得出它们的和.但是以上的代码不行,该怎么改?
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input:");
//string x = Console.ReadLine();
int x, y;
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} + {0} = {0}", x, y, x + y);
Console.ReadKey();
}
}
}c#函数,输入两个数字x,y,得出它们的和.但是以上的代码不行,该怎么改?
这是什么玩意?
Console.WriteLine("{0} + {1} = {2}", x, y, x + y);
{
int x, y;
Console.WriteLine("input:");
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} + {1} = {2}", x, y, x + y); Console.ReadLine(); }
这一句 有问题...
Console.WriteLine("{0} + {1} = {2}", x, y, x + y);Console.WriteLine第一个参数stringformat中{0}对应后面的第一个参数(就是x),{1}对应着后面第二个参数(就是y),以此类推所以你全部写的{0},最后输出的是个1+1=1