Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Friday, 18 August 2017

Star Pattern Programs In Java

Java Star Pattern Programs

Star Pattern In Java

Here we will discuss some star pattern programs in java which will help you in java programming questions in an interview.

There can be any kind of pattern programs in java like number pattern programs in java, alphabet programs in java, etc. But here we will discuss only star(*) pattern programs in java.

so let's start with it.

Star Pattern 1:

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

Solution:

class Demo1
{
public static void main(String args[])
{
for(int i = 1; i<=8; i++)
{
for(int j = 1; j<i; j++)
{
System.out.println("*");
}
System.out.println();
}
}
}

Star Pattern 2:


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

* * * 
* *
*

Solution:

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

Star Pattern 3 :

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

Solution:

class Demo3
{
public static void main(String args[])
{
int number = 7;
int count = number - 1;
for(int k = 1; k<=number; k++)
{
for(int i = 1; i<=count; i++)
System.out.print(" ");
count--;
for(int i = 1; i<=2*k-1; i++)
System.out.print("*");
System.out.println();
}
}
}

Star Pattern 4:

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

Solution:

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

Star Pattern 5:



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

Solution:


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

Star Pattern 6:

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

Solution:

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

Star Pattern 7:

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

Solution:

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

Read More:

Alphabet Pattern Programs in Java.
Top 10 Java Number pattern Programs.
Top 10 Java Programming Interview Questions.
Basic Java Programs.

I hope, this star pattern in java will help you to increase your logical skill so that you can make your own desired star pattern programs in java.


Share:

23 comments:

  1. Thanks for all star pattern program in java. Nice java post.

    ReplyDelete
  2. How to write this pattern code in Java

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

    ReplyDelete
  3. How to write this pattern in java

    *
    *
    *
    *

    ReplyDelete
    Replies
    1. public class Program
      {
      public static void main(String[] args)
      {
      for(int i=1;i<=4;i++)
      {
      System.out.print("*");
      System.out.println();
      }


      }
      }

      Delete
  4. program for following pattern
    if n=4
    output is:
    1 2 3 4
    9 10 11 12
    13 14 15 16
    5 6 7 8

    ReplyDelete
  5. Could u post a program for equilateral triangle

    ReplyDelete
  6. How to write this pattern in java
    ********
    *aaaaaa*
    *aaaaaa*
    *aaaaaa*
    *aaaaaa*
    *aaaaaa*
    ********

    ReplyDelete
    Replies
    1. public static void main(String args[])
      {
      for(int i = 8; i>=1; i--)
      {
      for(int j = 1; j<=8; j++)
      {
      if(j==1||j==8||i==1)
      System.out.print("*");
      else
      System.out.print("a");


      }
      System.out.println("");
      }
      }

      Delete
  7. How to write this pattern in java? Pls. Answer me.

    *
    *
    * * *
    * *
    * *

    ReplyDelete
  8. how to write this pattern in java?

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

    ReplyDelete
  9. can i get a program for this patter?
    *****
    ****
    ***
    **
    *
    **
    ***
    ****
    *****

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

      System.out.println();
      }
      for(int i=2; i<=4; i++)
      {
      for(int j=1; j<=i; j++)
      {
      System.out.print("*");
      }

      System.out.println();
      }
      }

      }

      Delete
    2. /******************************************************************************

      Welcome to GDB Online.
      GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
      C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
      Code, Compile, Run and Debug online from anywhere in world.

      *******************************************************************************/
      public class Main
      {
      public static void main(String[] args) {
      int n=5;
      for(int i=0;i<=n;i++)
      {
      for(int j=0;j<=i;j++)
      {
      if(i==j)
      {
      System.out.print(i);
      }
      else
      {
      System.out.print(0);
      }
      }
      System.out.println();
      }

      }
      }

      Delete
  10. PLEASE HELP!!!!!!!!!
    How do i write this?
    *^^^^^^^^*
    **^^^^^^**
    ***^^^^***
    ****^^****
    **********

    ReplyDelete
  11. Hi, thanks for your blog, if you want to learn about programming languages like java, php, android app, embedded system etc. I think this training institute is the best one.
    Best java training in coimbatore
    Android training in coimbatore
    Networking training in coimbatore

    ReplyDelete
  12. Thanks for sharing this informative blog java training in OMR

    ReplyDelete
  13. This article regarding Print Star Pattern in Java is common for every java learner and thanks for sharing above codes in java programming.

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

    Please give code for above pattern Print Triangle of Stars in Java

    ReplyDelete
  14. nice post bro. I had written a similar post in c language. check once https://codingpointz.blogspot.com/2019/10/pattern-programs-in-c.html

    ReplyDelete
  15. *
    **
    ***
    use only one loop n solve this

    ReplyDelete
  16. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks!

    SS Total Anova Calculator
    derivative calculator
    Interval Calculator
    edublackboards

    ReplyDelete
  17. very very important programs for java interviews. Thanks

    ReplyDelete
  18. Thanks for sharing this blog. A great information you shared through this blog. Keep it up and best of luck for your future blogs and posts.
    Read my Article: https://www.metapunk.to/hema_yadav_41/cracking-the-code-your-journey-into-the-world-of-programming-languages-27b

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate