Re: [問題] 數字被吃一位?

看板C_Sharp作者 (Mr. Everything)時間14年前 (2009/10/06 14:58), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《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
感謝您的回答,kinwind先生已經替我解惑囉^^
10/07 02:21, 1F
文章代碼(AID): #1AokgWxa (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1AokgWxa (C_Sharp)