这个简单的程序输入整数并打印它们,但如果它看到60
则停止打印 string input = string.Empty;
int intValue = 0;
int[] numbers = new int[5];
for (int i = 0; i < 4; i++)
{
input = Console.ReadLine();
if (int.TryParse(input, out intValue))
numbers[i] = intValue;
}
for (int i = 0; i < numbers.Length; i++)
{
while (numbers[i] != 60)
{
Console.WriteLine(intValue);
}
}
程序在第4次输入后继续循环 像那样 输入: 1 2 3 4 4 4 4 4 4 ........等等
我不知道原因.... ^ _ ^
答案 0 :(得分:5)
while (numbers[i] != 60)
{
Console.WriteLine(intValue);
}
应该是:
if (numbers[i] != 60)
{
Console.WriteLine(intValue);
}
答案 1 :(得分:0)
string input = string.Empty;
int intValue = 0;
int[] numbers = new int[5];
for (int i = 0; i < 4; i++)
{
input = Console.ReadLine();
if (int.TryParse(input, out intValue))
numbers[i] = intValue;
}
for (int i = 0; i < numbers.Length; i++)
{
/*while (numbers[i] != 60)*/
if (numbers[i] != 60) // it should be if condition, while statement made it infinite
{
Console.WriteLine(intValue);
}
}