Domanda

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 ".");
È stato utile?

Soluzione 2

try this:

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

You need the + operator to concatenate string together.

Altri suggerimenti

Try this:

Console.Write("The sum of {0} and {1} is {2}.", number1, number2, total); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top