I am trying to get the sum of two numbers, but it is not displaying correctly. Here is the code:

int number1 = 1;
int number2 = 3;

Console.Write("The sum of " number1 "and" number2 "is" total ".");
有帮助吗?

解决方案 2

try this:

Console.Write("The sum of " + number1 + " and " + number2 + " is " + total +".");

You need the + operator to concatenate string together.

其他提示

Try this:

Console.Write("The sum of {0} and {1} is {2}.", number1, number2, total); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top