954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pyramid with a pattern

i have to do a pyramid with a pattern
like this
1
1 2 1
1 2 4 2 1
1 2 4 16 4 2 1

i just realized dani web didnt take my center pyrmaid thing it moved to the side no matter what spacing i did


this is the pattern but the height is not 4 as it is now, it is 8 and width is 15

so far i have done something like this

public class pyramid {
	public static void main(String args[]){
		int w = 8;
		for(int count =1; count<=w;count++){
			for(int a = 1; a<=w-count;a++){
				System.out.printf("   ");
				
			}
			for(int k = 1; k<=2*count -1;k++){
				System.out.printf(" 0 ");
			}
			System.out.println();
		}
		System.out.println();
	
	}

}


can someone please help me

ilovejava
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 2
 

ok i print 2^k

and i get


2
2 4 8
2 4 8 16 32
2 4 8 16 32 64 128
2 4 8 16 32 64 128 256 512
2 4 8 16 32 64 128 256 512 1024 2048
2 4 8 16 32 64 128 256 512 1024 2048 4096 8192
2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768

ilovejava
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 2
 

So the value in the middle of each line will be 2^(n-1)? What is the maximum you accept for the value of n? Because the n will be used to determine the height of the pyramid. Also, the value in the middle could have different length. How would you deal with 1 digit, 2 digits, 3 digits, 4 digits, etc in the same column?

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

hi morderators can delete this thread please!!
and any one from cos102 DONT COPY THIS ull get busted so will I
and I completed this problem btw................

ilovejava
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 2
 

how to make pattern like this :

                  1
                1 2 1
              1 2 4 2 1
            1 2 4 8 4 2 1
         1 2 4 8 16 8 4 2 1
      1 2 4 8 16 32 16 8 4 2 1
   1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
Ryomakun
Newbie Poster
1 post since May 2012
Reputation Points: 0
Solved Threads: 0
 

DaniWeb Member Rules include:
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules

Start your own thread.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: