【发布时间】:2020-08-19 21:30:28
【问题描述】:
但是,如果用户选择 1000 秒会占用太多空间。
我需要一种方法,让它自动将第一行更改为下面的数字。
这是我的计时器代码:
public class TimerExample
{
static int UserInputs()
{
int numberOfSeconds;
do
{
Console.WriteLine("How many seconds would you like the test to be? Please type a number divisible by 10!");
int.TryParse(Console.ReadLine(), out numberOfSeconds);
} while (numberOfSeconds % 10 != 0);
return numberOfSeconds;
}
public class TimerClass
{
public static int Timers(int timeLeft)
{
do
{
Console.WriteLine($"timeLeft: {timeLeft}");
timeLeft--;
Thread.Sleep(1000);
} while (timeLeft > 0);
return timeLeft;
}
}
public static void Main(string[] args)
{
int numberOfSeconds = UserInput();
TimerClass.Timers(numberOfSeconds);
}
}
如果您需要,这是我的完整代码: https://github.com/CrazyDanyal1414/mathstester
【问题讨论】:
-
使用
Console.Write代替Console.WriteLine -
@bradbury9
Console.Write()如果用户输入 10,将提供诸如10987654321的输出
标签: c# timer user-input