Triangle of Numbers
Pattern for N = 4
import java.util.Scanner;
public class TriangleOfNum {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n= s.nextInt();
int p=0;
int q=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
System.out.print(" ");
}
p=i;
for(int k=1;k<=i;k++)
{
System.out.print(p);
p++;
}
q=2*i-2;
for(int d = i-1; d>=1;d--)
{
System.out.print(q);
q--;
}
System.out.println();
}
}
}
Comments
Post a Comment