Given the number of rows, n, as input, write a program to print the following pattern.
expected output: 1 1 2 1 3 1 4 1 3 1 2 1
public static void main(String[] args) { int n = Integer.parseInt(args[0]); for(int i=1;i<=n;i++) { for(int j=0;j<n-i;j++) System.out.print(" "); System.out.print(1); for(int j=0;j<2*(i-1)-1;j++) System.out.print(" "); if(i!=1) System.out.print(i+1); System.out.println(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)