如何在控制台的同一行上从整数打印文本和值? [英] How to print Text and value from integer on the same line in the console?
本文介绍了如何在控制台的同一行上从整数打印文本和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的工作,但是没有用:
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.Writeline("The Money you have now are",money)
推荐答案
您有几种选择:
-
连接字符串:
Concatenate the strings:
Console.Writeline("The Money you have now are" + money);
使用 Console.WriteLine
:
Console.Writeline("The Money you have now are: {0}", money);
使用 控制台.改写
:
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);
这篇关于如何在控制台的同一行上从整数打印文本和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文