Home » JAVA solved programs

Java program to print Pattern of Stars



This section contains programs on Pattern of Stars, these programs will print different pattern of star series.

Pattern of Series Programs in Java

Program 1# Java program to print following pattern of series:

        *
       * *
      * * *
     * * * *
    * * * * *
public class PrintPattern
{
	public static void main(String args[])
	{
		int space=4;
		for(int i=1; i<=5; i++)
		{
			//print spaces
			for(int j=1; j<=space;j++)
				System.out.print(" ");
			
			//print stars
			for(int j=1; j<=i; j++)
				System.out.print("* ");
			
			//print new line
			System.out.println();
			space--;
			
		}
	}
}

Program 2# Java program to print following pattern of series:

    * * * * *
     * * * *
      * * *
       * *
        *    
public class PrintPattern
{
	public static void main(String args[])
	{
		int space=0;
		for(int i=5; i>=1; i--)
		{
			//print spaces
			for(int j=1; j<=space;j++)
				System.out.print(" ");
			
			//print stars
			for(int j=1; j<=i; j++)
				System.out.print("* ");
			
			//print new line
			System.out.println();
			space++;
			
		}
	}
}

Program 3# Java program to print following pattern of series:

    *        *
    **      **
    ***    ***
    ****  ****
    **********   
public class PrintPattern
{
	public static void main(String args[])
	{
		int space=8;
		for(int i=1; i<=5; i++)
		{
			//print first part of the row
			for(int j=1; j<=i; j++)
				System.out.print("*");
			
			//print space
			for(int j=1;j<=space; j++)
				System.out.print(" ");
				
			//print second part of the row
			for(int j=1; j<=i; j++)
				System.out.print("*");
			
			//print new lint
			System.out.println();	
			space=space-2;
		}
	}
}

Program 4# Java program to print following pattern of series:

    **********
    ****  ****
    ***    ***
    **      **
    *        *
public class PrintPattern
{
	public static void main(String args[])
	{
		int space=0;
		for(int i=5; i>=1; i--)
		{
			//print first part of the row
			for(int j=i; j>=1; j--)
				System.out.print("*");
			
			//print space
			for(int j=1;j<=space; j++)
				System.out.print(" ");
				
			//print second part of the row
			for(int j=i; j>=1; j--)
				System.out.print("*");
			
			//print new lint
			System.out.println();	
			space=space+2;
			
		}
	}
}

Program 5# Java program to print following pattern of series:

    **********
    ****  ****
    ***    ***
    **      **
    *        *
    *        *
    **      **
    ***    ***
    ****  ****
    **********
public class PrintPattern
{
	public static void main(String args[])
	{
		int space=0;
		for(int i=5; i>=1; i--)
		{
			//print first part of the row
			for(int j=i; j>=1; j--)
				System.out.print("*");
			
			//print space
			for(int j=1;j<=space; j++)
				System.out.print(" ");
				
			//print second part of the row
			for(int j=i; j>=1; j--)
				System.out.print("*");
			
			//print new lint
			System.out.println();	
			space=space+2;			
		}
		
		space=8;
		for(int i=1; i<=5; i++)
		{
			//print first part of the row
			for(int j=1; j<=i; j++)
				System.out.print("*");
			
			//print space
			for(int j=1;j<=space; j++)
				System.out.print(" ");
				
			//print second part of the row
			for(int j=1; j<=i; j++)
				System.out.print("*");
			
			//print new lint
			System.out.println();	
			space=space-2;
		}
		
	}
}





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.