任何一個可以告訴我爲什麼這個節目是給運行時錯誤:C#運行時錯誤
Unhandled Exception: System.FormatException: Input string was not in the correct format
at System.Int64.Parse (System.String s) [0x00000] in <filename unknown>:0
at Myclass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in the correct format
at System.Int64.Parse (System.String s) [0x00000] in <filename unknown>:0
at Myclass.Main (System.String[] args) [0x00000] in <filename unknown>:0
代碼:
static void Main(string[] args)
{
string test = Console.ReadLine().Trim();
long t = Int64.Parse(test);
while (t > 0)
{
t--;
string res = Console.ReadLine().Trim();
long n = Int64.Parse(res);
Console.WriteLine(n);
long ans = n * 8;
if (n > 1)
ans = ans + (n - 1) * 6;
Console.WriteLine(ans);
Console.WriteLine("\n");
}
}
,並輸入:
2
1 2
什麼是錯誤? – 2014-10-31 13:21:45
究竟是什麼例外?例如,你的代碼中的'Int64.Parse(test)'會引發'FormatException',你會輸入字母而不是數字。 – 2014-10-31 13:23:14
「輸入字符串的格式不正確」中的哪部分不明白? – 2014-10-31 13:24:05