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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 3 4 5 | 1 2 2 3 3 4 4 5 5 |