配列に格納されているすべての整数の中で、0 より大きい最小値を見つける必要があります。私はスタックオーバーフローでそれを行ういくつかの方法を試しましたが、私の最小値はすべての場合でまだ 0 です。コードを機能させるには、コードの何を変更すればよいですか?
int[] userInput = new int[1000];
int counter;
Console.WriteLine ("Please input some numbers");
for (counter = 0; counter < userInput.Length; counter++) {
string line = Console.ReadLine ();
if (line == "" || line == "stop") {
break;
} else {
int.TryParse (line, out userInput [counter]);
}
}
int min = 0;
for(int i = 0; i < userInput.Length; i++)
{
if(userInput[i] > 0)
{
userInput[i] = min;
break;
}
}
for(int i = 0; i < userInput.Length; i++)
{
if(userInput[i] < min && userInput[i] > 0)
{
min = userInput [i];
}
}
Console.WriteLine(min);
}
}
}
LINQを使わずにやりたいです。