每次循环重复打印不同的控制台。
一切都很好。如果用户输入多个重复第一个循环的问题,我希望这个问题说“请输入2号”,等等。是否可以在相同的console.writeline
中执行此操作?
using System;
namespace Looping
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("How many numbers will you provide?");
int numbersProvide = Convert.ToInt32(Console.ReadLine());
int i;
for (i = 0; i < numbersProvide; i++)
{
Console.WriteLine("Please enter number:");
int enterNum = Convert.ToInt32(Console.ReadLine());
int j;
int sum = 0;
double addDiv;
for (j = 1; j <= 25; j++)
{
if (enterNum % j == 0)
{
addDiv = enterNum / j;
Console.WriteLine(enterNum + " is divisible by " + j + "(" + addDiv + ")");
sum += j;
}
}
Console.WriteLine("The sum of the quotient is: " + sum);
}
Console.ReadKey();
}
}
}
Everything runs perfectly. If a user enters more than one to repeat the first for loop I want the question to say "Please enter number 2" and so forth. Is there way to do this within the same Console.WriteLine
?
using System;
namespace Looping
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("How many numbers will you provide?");
int numbersProvide = Convert.ToInt32(Console.ReadLine());
int i;
for (i = 0; i < numbersProvide; i++)
{
Console.WriteLine("Please enter number:");
int enterNum = Convert.ToInt32(Console.ReadLine());
int j;
int sum = 0;
double addDiv;
for (j = 1; j <= 25; j++)
{
if (enterNum % j == 0)
{
addDiv = enterNum / j;
Console.WriteLine(enterNum + " is divisible by " + j + "(" + addDiv + ")");
sum += j;
}
}
Console.WriteLine("The sum of the quotient is: " + sum);
}
Console.ReadKey();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用循环的索引变量
i
Just use the index variable
i
of your loop