DIGIT-ARC read-only archive · snapshot: July 23, 2026

How to print a sequence?

5 posts · originally from https://geek.digit.in/community/threads/how-to-print-a-sequence.162215/

Maddd
Maddd Original post #1
Aug 24, 2012 at 12:34 AM
Can anyone tell me how the following sequence can be printed in java or c?

*_________*
**______**
***___***
********
sharang.d
Aug 24, 2012 at 12:57 AM
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.
Maddd
Maddd #3
Aug 24, 2012 at 8:23 AM
Code:
outermost loop(no. of lines)
{
    loop1()   //prints 1st set of stars
    {}
    loop2()  //prints set of spaces
    {}
    loop3()  //prints 2nd set of stars
   {}
}


Thanks! It work my friend.
vickybat
Aug 28, 2012 at 12:27 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.
sharang.d
Aug 28, 2012 at 12:38 AM
Thanks! It work my friend.

Welcome :)
Once you get the general idea you can easily think about the code for any pattern.
Good luck!