I need help on creating a pyramid | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

I need help on creating a pyramid

Hi! I can't seem to produce this output. Any help will be appreciated. 1 2 4 6 3 6 9 12 15 4 8 12 16 20 24 28

23rd Apr 2020, 9:47 AM
Christian Campos (Eric)
Christian Campos (Eric) - avatar
3 Réponses
+ 2
What you tried so far..? Can we see..? For j=1 to 2*n Do print spaces in n-r and n+r values of j, else print number..
23rd Apr 2020, 10:54 AM
Jayakrishna 🇮🇳
0
this is what I got so far. int rowss=5, kk=0; for(int ii=1; ii<=rows; ++ii, kk=0) { for(int spacee=1; spacee<=rowss-ii; ++spacee) { System.out.print(" "); } int number=1; while(kk!=2*ii-1) { System.out.print(number+" "); number++; ++kk; } System.out.println();
23rd Apr 2020, 10:57 AM
Christian Campos (Eric)
Christian Campos (Eric) - avatar
0
Set int number=ii; //instead of int number=1; In while loop, change number++ to number = number + ii;
23rd Apr 2020, 2:11 PM
Jayakrishna 🇮🇳