使用while循环的表 [英] tables using while loop
本文介绍了使用while循环的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用while循环从1到10打印表格,但是我的代码无法正常工作,这是什么错误?
i am trying to print tables from 1 to 10 using while loop but my code is not working what mistake i am doing?
推荐答案
您好,您要输出1到10 * 1到10的所有乘积吗?如果是这样,请在内循环之后重置变量j:
Hi, do you want to output all products from 1 to 10 * 1 to 10? If so reset the variable j after the inner loop:
int i = 1;
int j = 1;
while (i <= 10)
{
while (j <= 10)
{
Console.WriteLine("{0}*{1}={2}", i, j, i * j);
j++;
}
Console.WriteLine();
i++;
j = 1;
}
Console.ReadLine();
另一个选择-我要做的-是使用for循环.
The other option - what I'd do - is to use for-loops.
for(int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10; j++)
{
Console.WriteLine("{0}*{1}={2}", i, j, i * j);
}
Console.WriteLine();
}
Console.ReadLine();
此致
Thorsten
Thorsten
这篇关于使用while循环的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文