Pattern coding questions with solutions

Pattern coding questions

In this blog , we will discuss about variety of patterns coding problems asked in multiple interviews like star patterns, number patterns, alphabetic patterns etc.

You should additionally give equal weightage on this pattern programming section. I don’t think that in an interview, recruiter won’t ask question cognate to this section if they are recruiting you as a software developer/software engineering profile.

Most of the time they endeavor to ask questions like write a program to print a given pattern.

Below questions are solved in Java and only loops logic are written which can be used anywhere in your program in different platforms and language.

1. Right angle triangle star pattern

* 
* * 
* * * 
* * * * 
* * * * * 
    for (i=0;i<5;i++)
        {
            for(j=0;j<=i;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }

2. Inverse Right angle triangle star pattern

* * * * * 
* * * * 
* * * 
* * 
* 
  for (i=5;i>0;i--)
        {
            for(j=0;j<i;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }

3. Right angle triangle star pattern

          * 
        * * 
      * * * 
    * * * * 
  * * * * * 
 for (i=0;i<5;i++)
        {
            for(j=5;j>i;j--)
            {
                System.out.print("  ");
            }
            for(int k=0;k<=i;k++)
            {
                System.out.print("* ");
            }
            System.out.println();

        }

4. Inverse Right angle triangle star pattern

* * * * * 
  * * * * 
    * * * 
      * * 
        * 
  for (i=0;i<5;i++)
        {
            for(j=0;j<i;j++)
            {
                System.out.print("  ");
            }
            for(int k=5;k>i;k--)
            {
                System.out.print("* ");
            }
            System.out.println();

        }

5. Full pyramid star pattern

          * 
        * * * 
      * * * * * 
    * * * * * * * 
  * * * * * * * * * 
for (i=0;i<5;i++)
        {
            for(j=5;j>i;j--)
            {
                System.out.print("  ");
            }
            for(int k=0;k<i;k++)
            {
                System.out.print("* ");
            }
            for(int k=0;k<=i;k++)
            {
                System.out.print("* ");
            }
            System.out.println();

        }

6. Reverse Full pyramid star pattern

* * * * * * * * * * * 
  * * * * * * * * * 
    * * * * * * * 
      * * * * * 
        * * * 
          * 
 for (i=0;i<=5;i++)
        {
           for(j=0;j<i;j++)
           {
               System.out.print("  ");
           }
           for(j=i;j<5;j++)
           {
               System.out.print("* ");
           }
            for(j=i;j<=5;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }

7. Floyd’s Triangle

1 
2 3 
4 5 6 
7 8 9 10 
        int l=0;
        for (i=0;i<5;i++)
        {
           for(j=0;j<i;j++)
           {
               System.out.print(l+1 +" ");
               l++;
           }
            System.out.println();
        }

8. Square star pattern

* * * * * 
* * * * * 
* * * * * 
* * * * * 
* * * * *
   for (i=0;i<5;i++)
        {
            for(j=0;j<5;j++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }

9. Increasing power of 2 pattern

*
**
****
********
****************
for (i=0;i<5;i++)
        {
            for(j=0;j<(Math.pow(2,i));j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }

10. Number pattern

1    
2  2    
3  3  3    
4  4  4  4    
5  5  5  5  5   
	for(i=1,p=1;i<=5;i++,p++)
  		{
  			for(j=1;j<=i;j++)
  			{
  				System.out.print(p+"  ");
  			}
  			System.out.println("  ");
  		}

Now after practicing all above questions, can you create Christmas tree pattern ? If not check this out.

Thank you for reading this article so far, if you know some other way to write above programs then you can leave a comment here or mail us at technonamecontact@gmail.com, So anyone can a get chance to publish their code on our website. As a result, one can improve knowledge and spread it to others

Please check most asked programming questions of strings with examples by clicking here, after that you might get a deep knowledge about string operations, in short, it will be helpful in clearing the interview.

For understanding the most important concept of data structures in an easy way you can check this article on our website.

If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.

You can also follow us on Twitter for daily updates.

Leave a Reply

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