Java Number Pattern (Hill shape 2)

In this tutorial, we will go through the hill shape numeric pattern program in java. Before that, you may go through the following topic in java.

Number Pattern:

public class Main
{
  public static void main(String args[])
  {
    int row = 5;
    int x = row;
    int y = row;
    int i, j;

    for (i = 1; i <= row; i++)
    {
      for (j = 1; j <= row * 2; j++)
      {
        if (j == x || j == y)
          System.out.print(x);
        else
          System.out.print(" ");
      }

      x--;
      y++;

      System.out.println();
    }
  }
}

Output:

        5
      4   4
    3       3
  2           2
1               1