1
121
12321
1234321
print this pattern using Java programming, for loop
Answers
Answer:
public class Pyramid
{
public static void main(String[] args)
{
int i=0,j=0,n=6,k=0;
for(i=0; i<n; i++)
{
k=1;
for(j=0; j<(n+i); j++)
{
if(j<n-i-1)
System.out.print(" ");
else
{
System.out.print(""+k);
if(j<(n-1))
k++;
else
k--;
}
}
System.out.println(" ");
}
}
}
Explanation:
follow and like and mark as brainliest
import java.io.*;
public class Program
{
public static void main(String []args)
{
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n-1;j++)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++) {
System.out.print(j);
}
for(int j=i-1;j>=1;j--) {
System.out.print(j);
}
System.out.println();
}
}
}
output-
1
121
12321
1234321
123454321