In this tutorial, we will write a number pattern program in java. The patterns are half pyramid patterns with different combinations of numbers such as in increasing order, decreasing order, or more.
Before that, you may go through the following topic in java.
Inverted Half Pyramid using Numbers in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.util.Scanner; public class Main { public static void main(String[] args) { int rows; Scanner sc = new Scanner(System.in); System.out.print("Enter the no. of rows: "); rows = sc.nextInt(); for (int i = rows; i >= 1; --i) { for (int j = 1; j <= i; ++j) { System.out.print(j + " "); } System.out.println(); } } } |
Output:
1 2 3 4 5 6 | Enter the no. of rows: 5 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 |