i am trying to make this shape using java
**********************
**********************
*****************
***************
************
***************
******************
i have TRIED at the bottom as u can see but i am unable to get this shape
i am confused

public class courseforuni 
{
	public static void main (String [] args)
	{
		int a=5;
		for(int i=0; i<=a; i++)
		{
			for(int j=0; j<=a; j++)
			{
				if((i+j)<=a)
				{
					System.out.println ("*");
				}
				else
				{
					System.out.print("");
				}
			}
			System.out.print ("");

Edited 4 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

Next time wrap your code in code tags and properly indent it

You should make an inner loop work according the number showing at the outer loop
Pseudo:

for(int i=0;i<7;i++){   //outer loop
    if(i==0 ||  i==1){                    //condition used to tell which loop to use
       for(int j=0;j<numberofstars;j++){  //inner loop used to print *
           System.out.print("*");
           }
       System.out.print("\n");   //just to show a newline
    }
    else if(i == 3){
         for(int j=0;j<anothernumberofstars;j++){
           System.out.print("*");
         }
          System.out.print("\n");   
    }
    //repeat steps for all iterations
}

Edited 4 Years Ago by zeroliken: n/a

Next time wrap your code in code tags and properly indent it

You should make an inner loop work according the number showing at the outer loop
Pseudo:

for(int i=0;i<7;i++){
    if(i==0 ||  i==1){
       for(int j=0;j<numberofstars;j++)
           System.out.print("*");
    }
    else if(i == 3){
         for(int j=0;j<anothernumberofstars;j++)
           System.out.print("*");
    }
    //repeat steps for all iterations
}

um thanks
i tried doing this program but whenever i put in for(int j=0;j<numberofstars;j++) i got number of stars underlined red which means wrong for(int j=0;j<anothernumberofstars;j++); i got another number of stars underlined in red and it said another number of stars cannot be resolved to a variable
}

Edited 4 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

It's only a code snippet and not complete its your job to change those variables to a number you want

I'm only showing it as a guide not as an answer

Edited 4 Years Ago by zeroliken: n/a

what do u mean repeat steps for all literations

do a condition when "i" is equal to 4,5,6, etc
where each condition's inner loop is used to print a specific nuber of "*"

Edited 4 Years Ago by zeroliken: n/a

do a condition when "i" is equal to 4,5,6, etc
where each condition's inner loop is used to print a specific nuber of "*"

i dont get it ????

i dont get it ????

else if(i == 4){
//another loop which prints a different number of  * 
}
else if(i == 5){
//another loop which prints a different number of  * 
}
//do this until all values of i is covered
else if(i == 4){
//another loop which prints a different number of  * 
}
else if(i == 5){
//another loop which prints a different number of  * 
}
//do this until all values of i is covered

so what number do i go tilll

till the last iteration of "i" (the outer loop counter)
in my example it's 6

Isn't it your job to manipulate your own code?

Edited 4 Years Ago by zeroliken: n/a

till the last iteration of "i" (the outer loop counter)
in my example it's 6

Isn't it your job to manipulate your own code?

thats all right

This article has been dead for over six months. Start a new discussion instead.