Question: I want to create a java program that names a shape of a christmas tree with asterisk. But my code is not outputing what i

I want to create a java program that names a shape of a christmas tree with asterisk. But my code is not outputing what i want

public static void main(String[] args){

String as = "*";

int n = 9;

int n2 = 17;

int n3 = 27;

for (int i =1; i<=n; i++) {

if(i%2!=0) {

for (int j=i; j<=(n+i)/2;j++) {

System.out.print(" ");

}

for (int k=1;k<=i;k++) {

System.out.print(as);

}

System.out.println();

}

}

for (int i = 7;i<=n2;i++) {

if(i%2!=0) {

for (int j =i;j<=(n2+i)/2;j++) {

System.out.print(" ");

}

for (int k =1; k<=i;k++) {

System.out.print(as);

}

System.out.println();

}

}

for (int i = 15;i<=n3;i++) {

if(i%2!=0) {

for (int j=i;j<=(n3+i)/2;j++) {

System.out.print(" ");

}

for (int k =1; k<=i;k++) {

System.out.print(as);

}

System.out.println();

}

}

for (int i =1;i<=4;i++) {

for(int k = 1; k<=12;k++) {

System.out.print(" ");

}

for(int k=1;k<=5;k++) {

System.out.print(as);

}

System.out.println();

}

}

------------------------------------------------------------------------------------------

output i want

 * *** ***** ******* ********* ******* ********* *********** ************* *************** ***************** *************** ***************** ******************* ********************* *********************** ************************* *************************** ***** ***** ***** ***** 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!