Write a java program to print following pattern

         1 
      1 2 1 
    1 2 3 2 1 
  1 2 3 4 3 2 1 

import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Row Size ");
int n=sc.nextInt();
for(int i=0;i<n;i++) {
int k=1,l=2*i-1;
for(int j=0;j<n-i;j++) {
System.out.print("  ");
}
for(int j=0;j<l;j++) {
System.out.print(k+" ");
if(j<l/2)
k++;
else
k--;
}
System.out.println();
}
}

}

Comments

Popular posts from this blog

program to calculate product of each column in matrix