0

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 by peter_budo: Keep It Clear - Do use code tags when posting any code

2
Contributors
12
Replies
13
Views
5 Years
Discussion Span
Last Post by zeroliken
0

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 by zeroliken: n/a

0

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 by peter_budo: Keep It Clear - Do use code tags when posting any code

0

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 by zeroliken: n/a

0

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 by zeroliken: n/a

0

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 ????

0

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
0
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

0

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 by zeroliken: n/a

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.