Java Number Pattern Programs

This page shows the list of Java Number Pattern Programs using for loop, while loop, functions, recursion, and class examples.

Please refer to the Learn Java and Java Programming Examples to get the basics and the complete list of programs. Refer to the URLs below for the remaining patterns, such as Star and Alphabet.

Java Number Pattern Programs

The following sections show the list of possible Java Number Pattern Programs along with the best possible example. However, use the hyperlink to check the remaining possible solutions for each program.

Java Simple Number Pattern Program

For more information on printing the Simple Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Simple Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.print(j + " ");
			}
			System.out.println();
		}
	}
}

Output

Simple Number Pattern Rows = 9
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 

Floyd’s Triangle

For more information on printing the Floyd’s Triangle >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		int number = 1;
		sc = new Scanner(System.in);
		
		System.out.print("Enter the Floyd Triangle Rows = ");
		int rows = sc.nextInt();

		for (int i = 1; i <= rows; i++) 
		{
			for (int j = 1; j <= i; j++) 
			{
				System.out.format("%d ", number);
				number++;
			}
			System.out.println("");
		}
	}
}

Output

Enter the Floyd Triangle Rows = 5
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 

Java Program to Print Diamond Number Pattern

For more information on printing the Diamond Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		int i;

		System.out.print("Enter Diamond Pattern Rows = ");
		int rows = sc.nextInt();

		for (i = 1; i <= rows; i++) {
			result(rows, i);
		}

		for (i = rows - 1; i > 0; i--) {
			result(rows, i);
		}
	}

	public static void result(int rows, int i) {
		for (int j = 1; j <= rows - i; j++) {
			System.out.print(" ");
		}
		for (int k = 1; k <= i * 2 - 1; k++) {
			System.out.print(k);
		}
		System.out.println();
	}
}

Output

Enter Diamond Pattern Rows = 5
    1
   123
  12345
 1234567
123456789
 1234567
  12345
   123
    1

Pyramid Numbers Pattern

For more information on printing the Pyramid Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Pyramid Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = rows; j > i; j-- ) 
			{
				System.out.print(" ");
			}
			for(int k = 1; k <= i; k++) 
			{
				System.out.print(i + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Pyramid Number Pattern Rows = 9
        1 
       2 2 
      3 3 3 
     4 4 4 4 
    5 5 5 5 5 
   6 6 6 6 6 6 
  7 7 7 7 7 7 7 
 8 8 8 8 8 8 8 8 
9 9 9 9 9 9 9 9 9 

Java Rectangle Number Pattern Programs

The following is the list of programs that print a rectangle of different kinds of numbers. This example shows how to print the Same Numbers in Rectangle Rows and Columns. For more information >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		System.out.print("Enter Numbers of Rows & Columns = ");
		int rows = sc.nextInt();
		int columns = sc.nextInt();

		for (int i = 1; i <= rows; i++) 
		{
			for (int j = i; j < i + columns; j++) 
			{
				System.out.printf("%d", j);
			}
			System.out.println();
		}
	}
}

Output

Enter Numbers of Rows & Columns = 5 5
12345
23456
34567
45678
56789

1 and 0 in Alternative Rectangle Columns

For more information on printing the 1 and 0 in Alternative Rectangle Columns >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		System.out.print("Enter Numbers of Rows & Columns = ");
		int rows = sc.nextInt();
		int columns = sc.nextInt();

		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= columns; j++ ) 	
			{
				if(j % 2 == 0) {
					System.out.printf("0 ");
				}
				else {
					System.out.printf("1 ");
				}
			}
			System.out.println();
		}
	}
}

Output

Java Number Pattern Programs

1 and 0 in Alternative Rectangle Rows

For more information on printing the 1 and 0 in Alternative Rectangle Rows >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		System.out.print("Enter Numbers of Rows & Columns = ");
		int rows = sc.nextInt();
		int columns = sc.nextInt();

		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= columns; j++ ) 	
			{
				if(i % 2 != 0) {
					System.out.printf("1");
				}
				else {
					System.out.printf("0");
				}
			}
			System.out.println();
		}
	}
}

Output

Enter Numbers of Rows & Columns = 8 15
111111111111111
000000000000000
111111111111111
000000000000000
111111111111111
000000000000000
111111111111111
000000000000000

Java Program to Print Box Number Pattern of 1 and 0

For more information on printing the Box Number Pattern of 1 and 0 >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		System.out.print("Enter Numbers of Rows & Columns = ");
		int rows = sc.nextInt();
		int columns = sc.nextInt();

		for(int i = 1; i <= rows; i++)
		{
			for(int j = 1; j <= columns; j++)
			{
				if(i == 1 || i == rows || j == 1 || j == columns)
				{
					System.out.print("1"); 
				}
				else
				{
					System.out.print("0"); 
				}
			}
			System.out.print("\n"); 
		}	
	}
}

Output

Enter Numbers of Rows & Columns = 9 16
1111111111111111
1000000000000001
1000000000000001
1000000000000001
1000000000000001
1000000000000001
1000000000000001
1000000000000001
1111111111111111

Hollow Box Number Pattern

For more information on printing the Hollow Box Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Number of Rows & Columns = ");
		int rows = sc.nextInt();	
		int columns = sc.nextInt();	
		
		for(int i = 1; i <= rows; i++)
		{
			for(int j = 1; j <= columns; j++)
			{
				if(i == 1 || i == rows || j == 1 || j == columns)
				{
					System.out.print("1 "); 
				}
				else
				{
					System.out.print("  "); 
				}
			}
			System.out.print("\n"); 
		}	
	}
}

Output

Enter Number of Rows & Columns = 9 13
1 1 1 1 1 1 1 1 1 1 1 1 1 
1                       1 
1                       1 
1                       1 
1                       1 
1                       1 
1                       1 
1                       1 
1 1 1 1 1 1 1 1 1 1 1 1 1 

Java Program to Print Pascal Number Triangle Pattern

For more information on printing the Pascal Triangle of numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Pascal Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 0 ; i < rows; i++ ) 
		{
			int number = 1;
			System.out.printf("%" + (rows - i) * 2 + "s", "");
			
			for (int j = 0 ; j <= i; j++ ) 	
			{
				System.out.printf("%4d", number);
				number = number * (i - j) / (j + 1);
			}
			System.out.println();
		}
	}
}

Output

Enter Pascal Triangle Number Pattern Rows = 6
               1
             1   1
           1   2   1
         1   3   3   1
       1   4   6   4   1
     1   5  10  10   5   1

Left Pascal Number Triangle

For more information on printing the Left Pascals Number Triangle >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Left Pascals Number Triangle Pattern Rows = ");
		rows = sc.nextInt();
				
		for (i = 1 ; i <= rows; i++ ) 
		{
			printItems(rows, i);
		}
		
		for (i = rows - 1; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = i ; j < rows; j++ ) 
		{
			System.out.print("  ");
		}
		for(int k = 1; k <= i; k++) 
		{
			System.out.print(k + " ");
		}
		System.out.println();
		
	}
}

Output

Enter Left Pascals Number Triangle Pattern Rows = 8
              1 
            1 2 
          1 2 3 
        1 2 3 4 
      1 2 3 4 5 
    1 2 3 4 5 6 
  1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
  1 2 3 4 5 6 7 
    1 2 3 4 5 6 
      1 2 3 4 5 
        1 2 3 4 
          1 2 3 
            1 2 
              1 

Java Program to Print Right Pascal Number Triangle Pattern

For more information on printing the Right Pascals Number Triangle >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Right Pascals Number Triangle Pattern Rows = ");
		rows = sc.nextInt();
				
		for (i = 1 ; i <= rows; i++ ) 
		{
			printItems(rows, i);
		}
		
		for (i = rows - 1; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = 1 ; j <= i; j++ ) 
		{
			System.out.print(j + " ");
		}
		System.out.println();
		
	}
}

Output

Enter Right Pascals Number Triangle Pattern Rows = 9
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 

Right Pascals Triangle of Multiplication Numbers Pattern

For more information on printing the Right Pascals Triangle of Multiplication Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Right Pascals Triangle Numeric Multiplication Rows = ");
		rows = sc.nextInt();
				
		for (i = 1 ; i <= rows; i++ ) 
		{
			printItems(rows, i);
		}
		
		for (i = rows - 1; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = 1 ; j <= i; j++ ) 
		{
			System.out.print(j * i + " ");
		}
		System.out.println();
		
	}
}

Output

Enter Right Pascals Triangle Numeric Multiplication Rows = 8
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
6 12 18 24 30 36 
7 14 21 28 35 42 49 
8 16 24 32 40 48 56 64 
7 14 21 28 35 42 49 
6 12 18 24 30 36 
5 10 15 20 25 
4 8 12 16 
3 6 9 
2 4 
1 

Right Pascals Triangle of Mirrored Numbers Pattern

For more information on printing the Right Pascals Triangle of Mirrored Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Right Pascals Triangle Mirrored Numbers Rows = ");
		rows = sc.nextInt();
				
		for (i = rows; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
		
		for (i = 2; i <= rows; i++ )  
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = i; j <= rows; j++ ) 
		{
			System.out.print(j + " ");
		}
		for(int k = rows - 1; k >= i; k--)
		{
			System.out.print(k + " ");
		}
		System.out.println();
		
	}
}

Output

Enter Right Pascals Triangle Mirrored Numbers Rows = 7
7 
6 7 6 
5 6 7 6 5 
4 5 6 7 6 5 4 
3 4 5 6 7 6 5 4 3 
2 3 4 5 6 7 6 5 4 3 2 
1 2 3 4 5 6 7 6 5 4 3 2 1 
2 3 4 5 6 7 6 5 4 3 2 
3 4 5 6 7 6 5 4 3 
4 5 6 7 6 5 4 
5 6 7 6 5 
6 7 6 
7 

Java Program to Print Right Triangle Number Pattern

For more information on printing the Right Triangle Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.printf("%d ", i);
			}
			System.out.println();
		}
	}
}

Output

Right Triangle Number Pattern Rows = 7
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
7 7 7 7 7 7 7 

Right Triangle of 1 and 0

For more information on printing the Right Triangle of 1 and 0 >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Triangle of 1 and 0 Pattern Rows = ");
		int rows = sc.nextInt();
			
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				if(j % 2 == 0) {
					System.out.print(0);
				}
				else {
					System.out.print(1);
				}
			}
			System.out.println();
		}
	}
}

Output

Enter Triangle of 1 and 0 Pattern Rows = 8
1
10
101
1010
10101
101010
1010101
10101010

Java Program to Print Right Triangle of Number in Reverse Pattern

For more information on printing the Right Triangle of Numbers in Reverse >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Reverse Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = rows ; i >= 1; i-- ) 
		{
			for (int j = rows ; j >= i; j-- ) 	
			{
				System.out.print(j + " ");
			}
			System.out.println();
		}
	}
}

Output

Reverse Right Triangle Number Pattern Rows = 9
9 
9 8 
9 8 7 
9 8 7 6 
9 8 7 6 5 
9 8 7 6 5 4 
9 8 7 6 5 4 3 
9 8 7 6 5 4 3 2 
9 8 7 6 5 4 3 2 1 

How to Print Consecutive Numbers in Right Triangle Columns?

For more information on printing the Consecutive Numbers in Right Triangle Columns >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Consecutive Numbers Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		int k = 1;
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.print(k++ + " ");
			}
			System.out.println();
		}
	}
}

Output

Consecutive Numbers Right Triangle Pattern Rows = 9
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 27 28 
29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 

How to Print Consecutive Numbers in Right Triangle Rows?

For more information on printing the Consecutive Numbers in Right Triangle Rows >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Consecutive Row Numbers Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			int val = i;
			
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.print(val + " ");
				val = val + rows - j;
			}
			System.out.println();
		}
	}
}

Output

Consecutive Row Numbers Right Triangle Pattern Rows = 9
1 
2 10 
3 11 18 
4 12 19 25 
5 13 20 26 31 
6 14 21 27 32 36 
7 15 22 28 33 37 40 
8 16 23 29 34 38 41 43 
9 17 24 30 35 39 42 44 45 

Right Triangle of Incremented Numbers

For more information on printing the Right Triangle of Incremented Numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Right Triangle of Incremented Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = i ; j >= 1; j-- ) 	
			{
				System.out.printf("%d ", j);
			}
			System.out.println();
		}
	}
}

Output

Right Triangle of Incremented Numbers Rows = 9
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1 

Right Triangle of Mirrored Numbers Pattern

For more information on the Java program to print the Right Triangle of Mirrored Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Right Traingle Mirrored Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = 1; j <= i; j++ ) 
			{
				System.out.print(j + " ");
			}
			for(int k = i - 1; k >= 1; k--) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Right Traingle Mirrored Numbers Rows = 8
1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
1 2 3 4 5 6 5 4 3 2 1 
1 2 3 4 5 6 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 

Right Triangle of Numbers in Sine Wave Pattern

For more information on printing the Right Triangle of Numbers in Sine Wave Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);

		System.out.print("Enter Right Traingle of Numbers in Sine Wave Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			System.out.print(i + " ");
			int num = i;
			
			for (int j = 1; j < i; j++ ) 
			{
				if(j % 2 != 0)
				{
					System.out.print((num + ((2 * (rows - i + 1)) - 1)) +" ");
					num = num + ((2 * (rows - i + 1)) - 1);
				}
				else
				{
					System.out.print((num + 2 * (i - j)) +" ");
					num = num + 2 * (i - j);
				}
			}
			System.out.println();
		}
	}
}

Output

Enter Right Traingle of Numbers in Sine Wave Rows = 8
1 
2 15 
3 14 16 
4 13 17 26 
5 12 18 25 27 
6 11 19 24 28 33 
7 10 20 23 29 32 34 
8 9 21 22 30 31 35 36 

Java Program to Print Right Triangle of Fibonacci Series Number Pattern

For more information on printing the Right Triangle of the Fibonacci Series Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Right Triangle Fibonacci Numbers Rows = ");
		int rows = sc.nextInt();
			
		for(int i = 1; i <= rows; i++)  
		{
			int First_Value = 0;
			int Second_Value = 1;
			for(int j = 1; j <= i; j++)
			{
				int Next = First_Value + Second_Value; 
				System.out.print(Next + " ");
                First_Value = Second_Value;
                Second_Value = Next;
			}
			System.out.println();
		}
	}
}

Output

Enter Right Triangle Fibonacci Numbers Rows = 9
1 
1 2 
1 2 3 
1 2 3 5 
1 2 3 5 8 
1 2 3 5 8 13 
1 2 3 5 8 13 21 
1 2 3 5 8 13 21 34 
1 2 3 5 8 13 21 34 55 

Inverted Right Triangle Number Pattern

For more information on printing the Inverted Right Triangle Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Inverted Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = rows ; i >= 1; i-- ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.printf("%d ", i);
			}
			System.out.println();
		}
	}
}

Output

Inverted Right Triangle Number Pattern Rows = 9
9 9 9 9 9 9 9 9 9 
8 8 8 8 8 8 8 8 
7 7 7 7 7 7 7 
6 6 6 6 6 6 
5 5 5 5 5 
4 4 4 4 
3 3 3 
2 2 
1 

Java Program for Inverted Right Triangle Number in Reverse Pattern

For more information on printing the Inverted Right Triangle Numbers in Reverse >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Inverted Right Triangle Reverse Numbers Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = rows ; j >= i; j-- ) 	
			{
				System.out.print(j + " ");
			}
			System.out.println();
		}
	}
}

Output

Inverted Right Triangle Reverse Numbers Pattern Rows = 9
9 8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 
9 8 7 6 5 4 3 
9 8 7 6 5 4 
9 8 7 6 5 
9 8 7 6 
9 8 7 
9 8 
9 

Inverted Right Triangle of Consecutive Numbers

For more information on printing the Inverted Right Triangle of Consecutive Numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Inverted Right Triangle Consecutive Number Pattern Rows = ");
		int 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

Inverted Right Triangle Consecutive Number Pattern Rows = 8
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 

Inverted Right Triangle of Decreasing Order Numbers

For more information on printing the Inverted Right Triangle of Decreasing Order Numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Inverted Right Triangle of Descreasing Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = rows ; i >= 1; i-- ) 
		{
			for (int j = i ; j >= 1; j-- ) 	
			{
				System.out.print(j + " ");
			}
			System.out.println();
		}
	}
}

Output

Inverted Right Triangle of Descreasing Numbers Rows = 9
9 8 7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 

Java Program to Print Square Number Pattern

For more information on printing the Square Pattern of Numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Please Enter any Side of a Square : ");
		int side = sc.nextInt();	
			
		for(int i = 0; i < side; i++)
		{
			for(int j = 0; j < side; j++)
			{
				System.out.print("1 "); 
			}
			System.out.print("\n"); 
		}	
	}
}

Output

Please Enter any Side of a Square : 11
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 1 

Square With Diagonal Numbers Pattern

For more information on printing the Square With Diagonal Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square with Diagonal Numbers Side = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = 1; j < i; j++ ) 
			{
				System.out.print("0 ");
			}
			System.out.print(i + " ");
			
			for(int k = i; k < rows; k++) 
			{
				System.out.print("0 ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square with Diagonal Numbers Side = 9
1 0 0 0 0 0 0 0 0 
0 2 0 0 0 0 0 0 0 
0 0 3 0 0 0 0 0 0 
0 0 0 4 0 0 0 0 0 
0 0 0 0 5 0 0 0 0 
0 0 0 0 0 6 0 0 0 
0 0 0 0 0 0 7 0 0 
0 0 0 0 0 0 0 8 0 
0 0 0 0 0 0 0 0 9 

How to Print the Same Numbers on all Sides of a Square?

For more information on printing the Same Numbers on all Sides of a Square >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter the Maximum Number of a Square = ");
		int rows = sc.nextInt();		
		int i;
		
		for (i = 1 ; i <= rows; i++ ) 
		{
			result(rows, i);
		}
		
		for (i = rows - 1 ; i >= 1; i-- ) 
		{
			result(rows, i);
		}
	}
	public static void result(int rows, int i) {
		int min;
		for (int j = 1 ; j <= rows; j++ ) 	
		{
			min = i < j? i:j;
			System.out.print(rows - min + 1 + " ");
		}
		for(int k = rows - 1; k >= 1; k--)
		{
			min = i < k? i:k;
			System.out.print(rows - min + 1 + " ");
		}
		System.out.println();
		
	}
}

Output

Enter the Maximum Number of a Square = 7
7 7 7 7 7 7 7 7 7 7 7 7 7 
7 6 6 6 6 6 6 6 6 6 6 6 7 
7 6 5 5 5 5 5 5 5 5 5 6 7 
7 6 5 4 4 4 4 4 4 4 5 6 7 
7 6 5 4 3 3 3 3 3 4 5 6 7 
7 6 5 4 3 2 2 2 3 4 5 6 7 
7 6 5 4 3 2 1 2 3 4 5 6 7 
7 6 5 4 3 2 2 2 3 4 5 6 7 
7 6 5 4 3 3 3 3 3 4 5 6 7 
7 6 5 4 4 4 4 4 4 4 5 6 7 
7 6 5 5 5 5 5 5 5 5 5 6 7 
7 6 6 6 6 6 6 6 6 6 6 6 7 
7 7 7 7 7 7 7 7 7 7 7 7 7 

How to Print the Same Numbers in Square Rows and Columns?

For more information on printing the Same Numbers in Square Rows and Columns >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Square Side = ");
		int rows = sc.nextInt();
				
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = i ; j < rows + 1; j++ ) 	
			{
				System.out.print(j + " ");
			}
			for(int k = 1; k < i; k++)
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square Side = 8
1 2 3 4 5 6 7 8 
2 3 4 5 6 7 8 1 
3 4 5 6 7 8 1 2 
4 5 6 7 8 1 2 3 
5 6 7 8 1 2 3 4 
6 7 8 1 2 3 4 5 
7 8 1 2 3 4 5 6 
8 1 2 3 4 5 6 7 

Java Program for Square of Left Decrement Number Pattern

For more information on printing the Square of Left Decrement Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square of Left Dec Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = rows; i >= 1; i-- ) 
		{
			for (int j = i; j < rows; j++ ) 
			{
				System.out.print(j + " ");
			}
			for(int k = rows - i; k < rows; k++) 
			{
				System.out.print(rows + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square of Left Decrement Numbers Rows = 9
9 9 9 9 9 9 9 9 9 
8 9 9 9 9 9 9 9 9 
7 8 9 9 9 9 9 9 9 
6 7 8 9 9 9 9 9 9 
5 6 7 8 9 9 9 9 9 
4 5 6 7 8 9 9 9 9 
3 4 5 6 7 8 9 9 9 
2 3 4 5 6 7 8 9 9 
1 2 3 4 5 6 7 8 9 

Square of Left Shift Numbers Pattern

For more information on printing the Square of Left Shift Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Left Shift Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++) 
		{
			for (int j = i; j <= rows; j++ ) 
			{
				System.out.print(j + " ");
			}
			for(int k = 1; k < i; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square Left Shift Numbers Rows = 9
1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 1 
3 4 5 6 7 8 9 1 2 
4 5 6 7 8 9 1 2 3 
5 6 7 8 9 1 2 3 4 
6 7 8 9 1 2 3 4 5 
7 8 9 1 2 3 4 5 6 
8 9 1 2 3 4 5 6 7 
9 1 2 3 4 5 6 7 8 

Square of Right Increment Numbers Pattern

For more information on printing the Square of Right Increment Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square of Right Increment Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = 1; j <= rows - i; j++ ) 
			{
				System.out.print(1 + " ");
			}
			for(int k = 1; k <= i; k++) 
			{
				System.out.print(i + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square of Right Increment Numbers Rows = 8
1 1 1 1 1 1 1 1 
1 1 1 1 1 1 2 2 
1 1 1 1 1 3 3 3 
1 1 1 1 4 4 4 4 
1 1 1 5 5 5 5 5 
1 1 6 6 6 6 6 6 
1 7 7 7 7 7 7 7 
8 8 8 8 8 8 8 8 

Square of Right Decrement Numbers Pattern

For more information on printing the Square of Right Decrement Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Right Decrement Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = rows; i >= 1; i-- ) 
		{
			for (int j = rows; j >= i; j-- ) 
			{
				System.out.print(j + " ");
			}
			for(int k = rows - i + 1; k < rows; k++) 
			{
				System.out.print(i + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square Right Decrement Numbers Rows = 9
9 9 9 9 9 9 9 9 9 
9 8 8 8 8 8 8 8 8 
9 8 7 7 7 7 7 7 7 
9 8 7 6 6 6 6 6 6 
9 8 7 6 5 5 5 5 5 
9 8 7 6 5 4 4 4 4 
9 8 7 6 5 4 3 3 3 
9 8 7 6 5 4 3 2 2 
9 8 7 6 5 4 3 2 1 

Square of Numbers in Sine Wave Pattern

For more information on printing the Square of Numbers in Sine Wave Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Numbers in Sine Wave Pat Side = ");
		int rows = sc.nextInt();
				
		for (int i = 0; i < rows; i++ ) 
		{
			for (int j = 0; j < rows; j++ ) 
			{
				if(j % 2 == 0)
				{
					System.out.print((rows * j) + i + 1 + " ");
				}
				else
				{
					System.out.print((rows * (j + 1)) - i + " ");
				}	
			}
			System.out.println();
		}
	}
}

Output

Enter Square Numbers in Sine Wave Pat Side = 6
1 12 13 24 25 36 
2 11 14 23 26 35 
3 10 15 22 27 34 
4 9 16 21 28 33 
5 8 17 20 29 32 
6 7 18 19 30 31 

Left Shift the Square Pattern of Odd Numbers

For more information on the Left Shifting the Square Pattern of Odd Numbers >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Square Left Shift Odd Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++) 
		{
			for (int j = i - 1; j < rows; j++ ) 
			{
				System.out.print(j * 2 + 1 + " ");
			}
			for(int k = 0; k < i - 1; k++) 
			{
				System.out.print(k * 2 + 1 + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Square Left Shift Odd Numbers Rows = 9
1 3 5 7 9 11 13 15 17 
3 5 7 9 11 13 15 17 1 
5 7 9 11 13 15 17 1 3 
7 9 11 13 15 17 1 3 5 
9 11 13 15 17 1 3 5 7 
11 13 15 17 1 3 5 7 9 
13 15 17 1 3 5 7 9 11 
15 17 1 3 5 7 9 11 13 
17 1 3 5 7 9 11 13 15 

Java Program to Print Triangle Number Pattern

For more information on printing the Triangle Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = rows; j > i; j-- ) 
			{
				System.out.print(" ");
			}
			for(int k = 1; k <= i; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Triangle Number Pattern Rows = 8
       1 
      1 2 
     1 2 3 
    1 2 3 4 
   1 2 3 4 5 
  1 2 3 4 5 6 
 1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 

Triangle of Numbers in Reverse Pattern

For more information on printing the Triangle of Numbers in Reverse Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Triangle of Numbers in Reverse Rows = ");
		int rows = sc.nextInt();
		
		for (int i = rows; i >= 1; i-- ) 
		{
			for (int j = 1; j < i; j++ ) 
			{
				System.out.print(" ");
			}
			for(int k = i; k <= rows; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Triangle of Numbers in Reverse Rows = 9
        9 
       8 9 
      7 8 9 
     6 7 8 9 
    5 6 7 8 9 
   4 5 6 7 8 9 
  3 4 5 6 7 8 9 
 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 

Java Program to Print Triangle of Mirrored Number Pattern

For more information on printing the Triangle of Mirrored Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Traingle Mirrored Numbers Rows = ");
		int rows = sc.nextInt();
		
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = rows; j > i; j-- ) 
			{
				System.out.print(" ");
			}
			for(int k = 1; k <= i; k++) 
			{
				System.out.print(k);
			}
			for(int l = i - 1; l >= 1; l--)
			{
				System.out.print(l);
			}
			System.out.println();
		}
	}
}

Output

Enter Traingle Mirrored Numbers Rows = 8
       1
      121
     12321
    1234321
   123454321
  12345654321
 1234567654321
123456787654321

Downward Triangle Mirrored Numbers Pattern

For more information on printing the Downward Triangle Mirrored Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Downward Traingle Mirrored Numbers Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = i; j <= rows; j++ ) 
			{
				System.out.print(j + " ");
			}
			for(int k = rows - 1; k >= i; k--) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Downward Traingle Mirrored Numbers Rows = 9
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 
2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 
3 4 5 6 7 8 9 8 7 6 5 4 3 
4 5 6 7 8 9 8 7 6 5 4 
5 6 7 8 9 8 7 6 5 
6 7 8 9 8 7 6 
7 8 9 8 7 
8 9 8 
9

Inverted Triangle Numbers Pattern

For more information on printing the Inverted Triangle Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Inverted Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1; i <= rows; i++ ) 
		{
			for (int j = 1; j < i; j++ ) 
			{
				System.out.print(" ");
			}
			for(int k = 1; k <= rows - i + 1; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter Inverted Triangle Number Pattern Rows = 9
1 2 3 4 5 6 7 8 9 
 1 2 3 4 5 6 7 8 
  1 2 3 4 5 6 7 
   1 2 3 4 5 6 
    1 2 3 4 5 
     1 2 3 4 
      1 2 3 
       1 2 
        1 

Remaining Java Number Pattern Programs

The following is a list of remaining number pattern programs that display in different shapes.

K Shape Number Pattern

For more information on printing the K Shape Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter K Shape Number Pattern Rows = ");
		rows = sc.nextInt();
				
		for (i = rows; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
		
		for (i = 2; i <= rows; i++ )  
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = 1 ; j <= i; j++ ) 	
		{
			System.out.print(j+ " ");
		}
		System.out.println();
		
	}
}

Output

Enter K Shape Number Pattern Rows = 7
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 

Left Arrow Numbers Pattern

For more information on printing the Left Arrow Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Left Arrow Number Pattern Row = ");
		rows = sc.nextInt();
				
		for (i = rows; i >= 1; i-- ) 
		{
			printItems(rows, i);
		}
		
		for (i = 2; i <= rows; i++ )  
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = i ; j >= 1; j-- ) 	
		{
			System.out.print(j+ " ");
		}
		System.out.println();
		
	}
}

Output

Enter Left Arrow Number Pattern Row = 8
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 

Right Arrow Number Pattern

For more information on printing the Right Arrow Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);	
		
		int i, j;
		
		System.out.print("Enter Right Arrow Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (i = 1 ; i <= rows; i++ ) 
		{
			for (j = 1 ; j <= rows; j++ ) 
			{
				if(j < i) {
					System.out.print(" ");
				}
				else {
					System.out.print(j);
				}
			}
			System.out.println();
		}
		
		for (i = 1 ; i < rows; i++ ) 
		{
			for (j = 1 ; j <= rows; j++ ) 
			{
				if(j < rows - i) {
					System.out.print(" ");
				}
				else {
					System.out.print(j);
				}
			}
			System.out.println();
		}
	}
}

Output

Enter Right Arrow Number Pattern Rows = 9
123456789
 23456789
  3456789
   456789
    56789
     6789
      789
       89
        9
       89
      789
     6789
    56789
   456789
  3456789
 23456789
123456789

Sandglass Number Pattern

For more information on printing the Sandglass Number Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, rows;
		
		System.out.print("Enter Sandglass Number Pattern Rows = ");
		rows = sc.nextInt();
				
		for (i = 1; i <= rows; i++ ) 
		{
			printItems(rows, i);
		}
		
		for (i = rows - 1; i >= 1; i-- )   
		{
			printItems(rows, i);
		}
	}
	public static void printItems(int rows, int i) {
		for (int j = 1 ; j < i; j++ ) 
		{
			System.out.print(" ");
		}
		for(int k = i; k <= rows; k++) 
		{
			System.out.print(k + " ");
		}
		System.out.println();		
	}
}

Output

Enter Sandglass Number Pattern Rows = 7
1 2 3 4 5 6 7 
 2 3 4 5 6 7 
  3 4 5 6 7 
   4 5 6 7 
    5 6 7 
     6 7 
      7 
     6 7 
    5 6 7 
   4 5 6 7 
  3 4 5 6 7 
 2 3 4 5 6 7 
1 2 3 4 5 6 7 

V Number Pattern

For more information on printing the V Numbers Pattern >> Click Here.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter V Shape Number Pattern Rows = ");
		int rows = sc.nextInt();
				
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 
			{
				System.out.print(j);
			}
			for (int k = 1; k <= 2 * (rows - i); k++ ) 
			{
				System.out.print(" ");
			}
			for (int l = i; l >= 1; l-- ) 
			{
				System.out.print(l);
			}
			System.out.println();
		}
	}
}

Output

Enter V Shape Number Pattern Rows = 9
1                1
12              21
123            321
1234          4321
12345        54321
123456      654321
1234567    7654321
12345678  87654321
123456789987654321