Re: [問題] 數字被吃一位?
※ 引述《Fnd (勸君莫回首)》之銘言:
: 請問,我寫
: static void Main(string[] args)
: {
: int i, x, y;
: while (Console.Read() != 0)
: {
: x = int.Parse(Console.ReadLine());
: Console.Write(x);
: }
: }
: 時,為何他會吃掉最前面一位數呢?
: ex:12345會跑出2345= =a
: 抱歉第一次使用c sharp問題有點noob...
由原文看起來似乎是要限定第一個數字不能是0?
如果是的話可以這樣作
static void Main(string[] args)
{
string x;
int y;
while ((y=Console.Read()) != -1)
{
x = Console.ReadLine();
if (y != 48)
x = Convert.ToChar(y) + x;
Console.WriteLine(x);
}
}
input: 028
ouput: 28
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.249.154.130
推
10/07 02:21, , 1F
10/07 02:21, 1F
討論串 (同標題文章)