Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

15+ pattern programs in Java programming

YASH PAL, 31 July 202419 February 2026

In this tutorial, we are going to write some pattern programs in java programming with practical program code and step-by-step full complete explanation.

15+ pattern programs in Java programming

First pattern program

 
class Pattern8
{
	public static void main(String args[])
	{
		int n, c, k, space, count = 1;
		space =n=5;
		for (c = 1; c <= n; c++)
		{
			for (k = 1; k < space; k++)
				System.out.print(" ");
			for (k = 1; k <= c; k++) {
				System.out.print("*");
			if (c > 1 && count < c)
			{
				System.out.print("A");
				count++;
			}
		}
			System.out.print("n");
			space--;
			count = 1;
		}
	}
}

Output

 
     *
     *A*
    *A*A*
   *A*A*A*
  *A*A*A*A*

Second pattern program.

 
class Pattern9
{
	public static void main(String args[])
	{
		int rows, i, j, number= 1;
		rows=4;
		for(i=1; i <= rows; i++)
		{
			for(j=1; j <= i; ++j)
			{
				System.out.print(number);
				++number;
			}
			System.out.print("n");
		}
	}
}

Output

 
1
23
456
78910

Third pattern program.

 
class Pattern10
{
	public static void main(String args[])
	{
		int rows, c = 1, space, i, j;
		rows=5;
		for(i=0; i<rows; i++)
		{
			for(space=1; space <= rows-i; space++)
			{
				System.out.print(" ");
			}
			for(j=0; j<=i; j++)
			{
				if (j==0 || i==0)
					c = 1;
				else
					c = c*(i-j+1)/j;
				System.out.print(" "+c);
			}
			System.out.print("n");
		}
	}
}

Output

      1
     1 1
    1 2 1
   1 3 3 1
  1 4 6 4 1

Fourth pattern program.

 
class Pattern11
{
	public static void main(String args[])
	{
		int i, space, rows, k=0, count = 0, count1 = 0;
		rows=5;
		for(i=1; i<=rows; ++i) 
		{
			for(space=1; space <= rows-i; ++space) 
			{
				System.out.print("  ");
				++count;
			}
			while(k != 2*i-1) 
			{
				if (count <= rows-1) 
				{
					System.out.print(" "+(i+k));
					++count;
				}
				else
				{
					++count1;
					System.out.print(" "+(i+k-2*count1));
				}
				++k;
			}
			count1 = count = k = 0;
			System.out.print("n");
		}
	}
}

Output

 

           1
         2 3 2
       3 4 5 4 3
     4 5 6 7 6 5 4
   5 6 7 8 9 8 7 6 5

Fifth pattern program.

 
class Pattern13
{
	public static void main(String args[])
	{
		for (int i=1; i<=5; i++)
		{
			for (int j=5; j>=i; j--) 
			{
				System.out.print(" ");
			}
			for (int k=1; k<=i; k++) 
			{
				System.out.print("*");
			}
			System.out.print("n");
		}
	}
}

Output

 
     *
    **
   ***
  ****
 *****

Sixth pattern program.

 
class Pattern14
{
	public static void main(String args[]) 
	{
		int i,j,k,sp=1;
		for (i=5; i>=1; i--) 
		{
			for (k=sp; k>=0; k--) 
			{
				System.out.print(" ");// only 1 space
			}
			for (j=i; j>=1; j--) 
			{
				System.out.print("*");
			}
			sp = sp + 1;
			System.out.print("n");
		}
	}
}

Output

 
*****
 ****
  ***
   **
    *

Seventh pattern program.

 
class Pattern15
{
	public static void main(String args[]) 
	{
		int i,j,k,sp=1;
		for (i=1; i<=5; i++) 
		{
			for (k=sp; k<=5; k++) 
			{
				System.out.print(" ");
			}
			for (j=0; j< i; j++) 
			{
				System.out.print("*");
			}
			sp = sp + 1;
			System.out.print("n");
		}
		sp = 1;
		for (i=4; i>=1; i--) 
		{
			for (k=sp; k>=0; k--) 
			{
				System.out.print(" ");
			}
			for (j=i; j>=1; j--) 
			{
				System.out.print("*");
			}
			sp = sp + 1;
			System.out.print("n");
		}
	}
}

Output

 
     *
    * *
   * * *
  * * * *
 * * * * *
  * * * *
   * * *
    * *
     *

Eight pattern program.

 
class Pattern16
{
	public static void main(String args[]) 
	{
		int i, j=5, k, x;
		for (i=1;i<=5;i++) 
		{
			for (k=1;k<=j;k++) 
			{
				System.out.print(" ");
			}
			for (x=1;x<=i;x++) 
			{
				System.out.print(i);
				System.out.print(" ");
			}
			System.out.print("n");
			j=j-1;
		}
	}
}

Output

 
     1 
    2 2 
   3 3 3 
  4 4 4 4 
 5 5 5 5 5

Ninth pattern program.

 
class Pattern17
{
	public static void main(String args[]) 
	{
		int i,j,k;
		for (i=1;i<=5;i++) 
		{
			for (j=5;j>=1;j--) 
			{
				if(j<=i)
					System.out.print(j);
				else
					System.out.print(" ");
			}
			System.out.print("n");
		}
	}
}

Output

 
    1
   21
  321
 4321
54321

Ten pattern program.

 
class Pattern18
{
	public static void main(String args[]) 
	{
		int i,j,k;
		for (i=1;i<=5;i++) 
		{
			for (j=1;j<=5;j++) 
			{
				if(j<=i)
					System.out.print(j);
				else
					System.out.print(" ");
			}
			for (j=5;j>=1;j--) 
			{
				if(j<=i)
					System.out.print(j);
				else
					System.out.print(" ");
			}
			System.out.print("n");
		}
	}
}

Output

1        1
12      21
123    321
1234  4321
1234554321

Eleven pattern program.

 
class Pattern19
{
	public static void main(String args[]) 
	{
		int i,j,k;
		for (i=1;i<=5;i++) 
		{
			j=i;
			for (k=1;k<=i;k++) 
			{
				System.out.print(j++);
			}
			System.out.print("n");
		}
	}
}

Output

1
23
345
4567
56789

Twelve pattern program.

 
class Pattern20
{
	public static void main(String args[]) 
	{
		int i,j;
		for (i=1;i<=4;i++) 
		{
			for (j=i;j>1;j--)
			System.out.print(j);
				for (j=1;j<=i;j++)
					System.out.print(j);
			System.out.print("n");
		}
	}
}

Output

 
1
212
32123
4321234

Thirteen pattern program.

 
class Pattern21
{
	public static void main(String args[]) 
	{
		int i,j;
		for (i=1;i<=5;i++) 
		{
			for (j=1;j<=5;j++) 
			{
				if(j==5 || j==1 || i==1 || i==5)
					System.out.print("1");
				else
					System.out.print(" ");
			}
			System.out.print("n");
		}
	}
}

Output

 
11111
1   1
1   1
1   1
11111

Fourteen pattern program.

 
class Pattern22
{
	public static void main(String args[]) 
	{
		int i, j, k;
		for (i=1;i<=5;i++) 
		{
			for (j=i;j<5;j++) 
			{
				System.out.print(" ");
			}
			for (k=1;k<(i*2);k++) 
			{
				System.out.print(k);
			}
			System.out.print("n");
		}
		for (i=4;i>=1;i--) 
		{
			for (j=5;j>i;j--) 
			{
				System.out.print(" ");
			}
			for (k=1;k<(i*2);k++)
			{
				System.out.print(k);
			}
			System.out.print("n");
		}
	}	
}

Output

 
       1
      123
     12345
    1234567
   123456789
    1234567
     12345
      123
       1

Fifteen pattern program.

 
class Pattern23
{
	public static void main(String args[]) 
	{
		int i,j;
		for (i=1;i<=10;i++) 
		{
			for (j=1;j<=i;j++) 
			{
				System.out.print(i*j);
			}
			System.out.print("n");
		}
	}
}

Output

 
1
24
369
481216
510152025
61218243036
7142128354249
816243240485664
91827364554637281
102030405060708090100

Sixteen pattern program.

 
class Pattern25
{
	public static void main(String args[]) 
	{
		int i, j, rows;
		/* Input number of rows from user */
		rows=8;
		for(i=1; i<=rows; i++) 
		{
			/* Print trailing spaces */
			for(j=1; j<=rows-i; j++) 
			{
				System.out.print(" ");
			}
			/* Print stars and center spaces */
			for(j=1; j<=rows; j++) 
			{
				if(i==1 || i==rows || j==1 || j==rows)
					System.out.print("*");
				else
					System.out.print(" ");
			}
			System.out.print("n");
		}
	}
}

Output

 
       ********
      *      *
     *      *
    *      *
   *      *
  *      *
 *      *
********
coding problems solutions Java Tutorials javaJava program

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Simple Java Program Example
Java Program to compare two numbers using if-else
Java Program for the Addition of Two Numbers
Java Program for Subtraction of Two Numbers
Java program to print fibonacci series
Java Program to check a prime number
Java Program to print N prime numbers
Java Program to check a palindrome number
Java Program to Print Student Marksheet
Java Program using Static variable and method
Java Program using an interface
Java Program to print the sum of command line arguments
Java Program for Handling an Exception
Java Swing program to calculate the square of a number
Java Program to use the equal function
Java Program to handle an action event
Java Program using a constructor
Java Program to print shapes using an applet
Java Program to generate random numbers between 1 and 100
Java Program for Method Overloading
Java Program using switch case
Java Program using an abstract class
Java Program to find the sum and product of the digits of a number
Java Program to find the sum of integers divisible by 7
Java Program to concatenate a string using a for loop
Java Program to display a multiplication table
Java Program to swap two values
Java Program to convert days into months
Java Program to find an Armstrong number
Java Program to print characters of integers
Java program to generate the Harmonic series
Java Program to find the average of consecutive N odd and even numbers
Java Program to take command-line arguments
Java program to use a class and an object
Java program using conditional operators
Java program to use this keyword
Java program using a double variable
Java program to use the super keyword
Java program to use a nested switch case
Java Program to check for a leap year
Java Program to print factorial
Java Program to print a list of even numbers
15+ Pattern programs in Java
Java Program to print FLOYD'S TRIANGLE
Java Program to print a star pattern in a square shape
Java Program to print a pyramid of numbers using a for loop
Java Program to print Even number between a range
Java Program to print the Fibonacci series using an array
Java Program to print a star pattern in a pyramid shape
Java Program to check if a list of numbers is a palindrome
Java program to print a star pattern in a reverse pyramid shape
Java program to print prime numbers between given range
Java Program to print a star pattern in a diamond shape
Java Program to print factorial using recursion
Java Program to calculate the area of a circle using radius
Java program to print a star pattern in a triangle shape
Java Program to print a star pattern in a reverse triangle shape
Java Program to print a number pattern in a triangle shape
Java Program to print a number pattern in a reverse triangle shape

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes