Java Number Pattern (Hill shape 1)

number pattern 1

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(i);
        else
          System.out.print(" ");
      }

      x--;
      y++;

      System.out.println();
    }
  }
}

Output:

        1
      2   2
    3       3
  4           4
5               5