I am able to print pyramid like this :
1 123 12345 1234567
Code i used to print the pyramid of numbers like a
Try this :)
int a = 1;
int b = 4;
int m = 4;
for (int i = 1; i <= 4; i++) {
for (int c = 1; c <= m; c++) {
text.append(" ");
}
for (int k = 1; k <= b; k++) {
String result = String.valueOf(k);
text.append(result);
}
a = a + 2;
b--;
m++;
text.append("\n");
}
Try this
int a = 1;
int b = 4;
for (int i = 1; i <= 4; i++) {
for (int k = a; k >= 1; k--) {
String result = String.valueOf(k);
text.append(result);
}
for (int c = 1; c <= b - 1; c++) {
text.append(" ");
}
a = a + 2;
b--;
text.append("\n");
}
System.out.println(text.reverse());
int numberofdigits = 7;
int numberofdigitsforrow = 0;
int Emptyspace = 0;
for (int i = 0; i < numberofdigits; i++)
{
numberofdigitsforrow = numberofdigits - i * 2;
if (numberofdigitsforrow > 0)
{
Emptyspace = numberofdigits-numberofdigitsforrow;
if (Emptyspace > 0)
{
for (int b = 1; b <= Emptyspace/2; b++)
{
Console.Write(" ");
}
}
for (int c = 1; c <= numberofdigitsforrow; c++)
{
Console.Write(c.ToString());
}
if (Emptyspace > 0)
{
for (int b = 1; b <= Emptyspace / 2; b++)
{
Console.Write(" ");
}
}
Console.WriteLine();
}
}
int w = 7;
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= 5; i++)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
//Printing i to rows value at the end of each row
for (int j = 1; j <=w; j++)
{
System.out.print(j+" ");
}
w = w - 2;
System.out.println();
}
try this ...
for (int i = 7; i > 0; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.print("\n");
if (i % 2 != 0) {
i = i - 1;
}
}