How to print Text and value from integer on the same line in the console?

后端 未结 2 870
一向
一向 2021-01-14 14:04

This is what I do, but it didn\'t work:

int money;
Console.Writeline(\"Enter how much money you want\";
money=int.Parse(Console.ReadLine());
Console.Writeli         


        
2条回答
  •  执念已碎
    2021-01-14 14:23

    You have several options:

    1. Concatenate the strings:

      Console.Writeline("The Money you have now are" + money);
      
    2. Use the format specifier version of Console.WriteLine:

      Console.Writeline("The Money you have now are: {0}", money);
      
    3. Use Console.Write instead:

      Console.Write("The Money you have now are: ");
      Console.Writeline(money);
      

    Note:

    Your code doesn't actually compile due to some missing parentheses, semi-colons and incorrect casing. I would write your code as this:

    Console.WriteLine("Enter how much money you want");
    int money = int.Parse(Console.ReadLine());
    Console.WriteLine("The Money you have now is {0}", money);
    

提交回复
热议问题