How to print a sequence?

Maddd

The Witcher
Can anyone tell me how the following sequence can be printed in java or c?

*_________*
**______**
***___***
********
 
Last edited:

sharang.d

Youngling
Code:
outermost loop(no. of lines)
{
    loop1()   //prints 1st set of stars
    {}
    loop2()  //prints set of spaces
    {}
    loop3()  //prints 2nd set of stars
   {}
}

Don't wanna spoon feed you so I've given you the general idea and not the actual code.
 

vickybat

I am the night...I am...
Can anyone tell me how the following sequence can be printed in java or c?

*_________*
**______**
***___***
********

Here you go mate (java implementation):

Code:
public class pyramid {
	
	public static void DesignPattern (int row){
		int i,j;
		
		for (i = 0; i <= row ;i++){
		for (j = 0 ;j<=i; j++){
			
			System.out.print("*");
			}
		for(j=0; j <=(row-i-1)*2 ;j++){
			System.out.print("__");
		}
		for (j=0; j<=i;j++){
		System.out.print("*");
	}
	
		System.out.println();
		
		}
		
	}
	public static void main (String[] args){
		
		DesignPattern(3);
	}
}

It gives the exact same pattern that you mentioned.
 
Top Bottom