public class Printer { // Create a class which its responsibility is to print requested string
public static void main(String[] args) { // The entry point of almost every java program
int end = 4; // As you want to print until 14
for (int counter = 1; counter <= end; ++counter) { // A for loop counts steps so far
for (int i = 0; i < counter; ++i) { // Here we print the number as many as counter
System.out.print(10 + counter%10 + ","); // System.out.print is a bulit in function which prints the given string
}
}
}
}
现在您可以在第三行中更改end的值,以获得更多的数字
# 2 楼答案
你还没有真正表明你自己做过任何工作。。。反正
for(int i = 0; i <= 4; i++){
for(int ii = 0; ii <=i; ii++){
int numbertoshow = 10+i;
System.out.print(numbertoshow+", ");
}
}
# 1 楼答案
您需要有一个计数器才能知道“到目前为止您打印了多少个数字”。 让我把它命名为
counter
。您必须将其声明为integer
现在,我们可以看到您的数字字符串有一个特殊的顺序,它看起来像:
counter%10 + 10
(其中%
符号表示为Modulo
计算)因此,现在您可以执行以下操作:
现在您可以在第三行中更改
end
的值,以获得更多的数字# 2 楼答案
你还没有真正表明你自己做过任何工作。。。反正
输出:
十,十一,十一,十二,十二,十三,十三,十三,十四,十四,十四,十四,
第一个循环指定结束数字(例如,如果i=0,10+i=10,则输出为10)。 第二个循环将使其重复输出(i)次(例如,如果i=2,10+i=12,则当ii等于0、1和2时,它将输出12次,因此为3次)
# 3 楼答案
# 4 楼答案
用这个
# 5 楼答案
我不想帮你做家庭作业,但请注意这里的模式。有110、211、312等
您需要一个从10开始到14结束的循环,如下所示:
但是你需要打印1、2、3、4或5次,而不是只打印一次。 一种方法是创建另一个变量,该变量从1开始,并随着i的增加而增加。然后创建另一个嵌套在第一个循环中的循环,该循环打印i那么多次。这应该足以让你开始。如果遇到麻烦,请随时提问
# 6 楼答案