代码:
该程序检查输入的2个数字是否可以被数字2 - 9整除,并显示剩余的可分数(不包括被查看的数字).
static void Main(string[] args) { for (int i = 2; i < 10; i++) { Challenge(2, 6, i); } Console.ReadLine(); } static void Challenge(int num1, int num2, int Divisor) { int sum = num1 + num2; bool SumDivisible = sum % Divisor == 0; bool num1Divisible = num1 % Divisor == 0; bool num2Divisible = num2 % Divisor == 0; int highNum = 80; ListNumbersDivisible = Enumerable.Range(1, highNum).Where(x => x % Divisor == 0).ToList(); // Use the booleans to determine output. if (SumDivisible || num1Divisible || num2Divisible) { if (SumDivisible) { Console.WriteLine("The SUM ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", sum, Divisor); outputListExceptInt(NumbersDivisible, sum); //output Console.WriteLine("\n\n"); } if (num1Divisible) { Console.WriteLine("The FIRST number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num1, Divisor); outputListExceptInt(NumbersDivisible, num1); //output Console.WriteLine("\n\n"); } if (num2Divisible) { Console.WriteLine("The SECOND number ({0}) is divisible by {1}! \nThe remaining USABLE numbers for {1} are:\n", num2, Divisor); outputListExceptInt(NumbersDivisible, num2); //output Console.WriteLine("\n\n"); } } else { Console.WriteLine("The NUMBERS chosen and their SUM are not divisble by {0}. \nThe USABLE numbers for {0} are:\n", Divisor); outputListExceptInt(NumbersDivisible); Console.WriteLine("\n\n"); } } public static void outputListExceptInt(List NumbersDivisibleByDivisor, int except = 0) { var Numbers = except > 0 ? NumbersDivisibleByDivisor.Where(x => x != except) : NumbersDivisibleByDivisor; foreach (int num in Numbers) { Console.WriteLine(num); } }
问题:
我发现当我将范围(highNum)设置为超过89的任何值时,窗口顶部的一个明显部分会被切断:
highNum = 89:
highNum = 90:
它只用那个小跳跃切断了6条线,我不知道为什么.
问题:
我最好的猜测是控制台窗口可以显示的输出必须有一些限制.这是正确的,还是导致此问题的其他原因?
在控制台窗口中,单击"默认值"
这将打开一个对话框,允许您在所有控制台窗口中默认设置回滚缓冲区大小(要保留的最大行数).
在我的屏幕截图中,它设置为9000,因为我经常将输出记录到控制台,有时需要能够向后滚动.
您还可以使用Console.SetBufferSize()从程序中为其运行的控制台修改它.