代码:
该程序检查输入的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;
List<int> NumbersDivisible = 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<int> NumbersDivisibleByDivisor, int except = 0)
{
var Numbers = except > 0 ? NumbersDivisibleByDivisor.Where(x => x != except) : NumbersDivisibleByDivisor;
foreach (int num in Numbers)
{
Console.WriteLine(num);
}
}
问题:
我发现当我将范围(highNum)设置为89以上的任何值时,窗口顶部的一个明显部分会被切断:
它只用那个小跳跃就切断了6条线,我不知道为什么。
问题:
我最好的猜测是控制台窗口可以显示的输出必须有一些限制。这是正确的,还是导致这个问题的其他原因?
答案 0 :(得分:7)
在控制台窗口中,单击“默认值”
这将打开一个对话框,允许您在所有控制台窗口中默认设置回滚缓冲区大小(要保留的最大行数)。
在我的屏幕截图中,它设置为9000,因为我经常将输出记录到控制台,有时需要能够向后滚动。
您也可以使用Console.SetBufferSize()从程序中为其运行的控制台修改它。
答案 1 :(得分:4)
答案 2 :(得分:1)
根据给定的here on microsoft's website修改答案:
你只有一个小缓冲区。