非常经典的A+B problem如何读取两个数?
题目中要求两个数之间可以用任意个空格、回车来分隔,多组数据。
请问应该如何读?比如C里scanf就行了,C++用cin,难不成在C#中还得一个个Console.Read()再判断不成?
[解决办法]
[解决办法]
- C# code
int pos = 0;int[] array = new int[5];Console.WriteLine("please input 5 numbers:");while (pos < 5){ string[] s = Console.ReadLine().Split(' '); for (int i = pos; i < pos + s.GetLength(0) && pos < 5; i++, pos++) array[i] = Convert.ToInt32(s[i - pos]);}Console.Write("\r\nyour entered: " + array[0]);for (int i = 1; i < 5; i++){ Console.Write(", " + array[i];}Console.WriteLine();