问题描述
我正在尝试使用for循环和嵌套for循环来制作圣诞树。对我来说,我需要能够用*来制作金字塔。我已经尝试了无数次,并且遇到了问题。这里是我的代码: 我试图做的是: 试试这个简单的代码: 它使用3个循环: I am trying to make a christmas tree using for loops and nested for loops. For me to do that I need to be able to make a pyramids with *. I have tried countless times and I am having problems making one. Here is my code: What I am trying to do is: Try this much simpler code: It uses 3 loops: 这篇关于使用for循环创建圣诞树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ b $ pre $ for(int i = 1; i for int j = 10; j> i; j - ){
System.out.println();
(int k = 1; k< = i; k ++){
System.out.print(*); (int h = 1; h )
(int l = 10; l }
}
System.out.println();
$ / code>
*
***
*****
*******
public class ChristmasTree {
public static void main(String [] args){
for(int i = 0 ; i for(int j = 0; j System.out.print();
for(int k = 0; k System.out.print(*);
System.out.println();
$ b $ p
$ b $ / p>
for(int i=1;i<=10;i++){
for(int j=10;j>i;j--){
System.out.println(" ");
}
for(int k=1;k<=i;k++){
System.out.print("*");
}
for(int l=10;l<=1;l++){
for(int h=1;h<=10;h++){
System.out.print(" ");
}
}
System.out.println();
}
*
***
*****
*******
public class ChristmasTree {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10 - i; j++)
System.out.print(" ");
for (int k = 0; k < (2 * i + 1); k++)
System.out.print("*");
System.out.println();
}
}
}