【发布时间】:2014-03-31 23:10:42
【问题描述】:
我真的很接近,但我似乎无法理解最后一步。 所以我想要的是拥有二维矩阵并只打印具有所有正整数的行。
现在我的代码只是取出 0 或负数的整数,但如果该行包含 0 或负数,我需要删除整行。
这就是我现在得到的
输入:
1 2 6 4
1 5 0 9
输出:
1 2 6 4
1 5
所以基本上它不应该打印第二行 b/c 它有一个非正整数
我做错了什么?
感谢您抽出时间来看看这个!
static void Main(string[] args)
{
// reads in multiples lines( array from console)
List<string> L = readAllLines();
// feeds read lines into matrix
int[,] m = convertListToIntMatrix(L);// feeds read lines into matrix
int Rows = m.GetLength(0);
int Cols = m.GetLength(1);
for (int r = 0; r < Rows; r++)
{
for (int c = 0; c < Cols; c++)
{
if (m[r, c] <= 0)
{
break;
}
else Console.Write("{0} ", m[r, c]);
}
Console.WriteLine();
}
【问题讨论】:
标签: c# arrays for-loop console