Pattern Space Pyramid Program in Java
public class Pattern45
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 6 - i; j++)
{
System.out.print(j);
}
for (int j = 3; j <= 2 * i-1; j++) { System.out.print(" "); } for (int j = 6-i; j >= 1; j--)
{
if (i == 1 && j == 5)
{
continue;
}
System.out.print(j);
}
System.out.println();
}
}
}
Output:
123454321 1234 4321 123 321 12 21 1 1
public class Pattern44
{
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++) { System.out.print(j); } for (int j = 9 - (2 * i); j >= 1; j--)
{
System.out.print(" ");
}
for (int j = i; j >= 1; j--)
{
if (i == 5 && j == 5)
{
continue;
}
System.out.print(j);
}
System.out.println();
}
}
}
Output:
1 1 12 21 123 321 1234 4321 123454321
b. tech. bca java java tutorials learn java mca