Java Star Pattern Programs
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.
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.
Thanks for all star pattern program in java. Nice java post.
ReplyDeleteHow to write this pattern code in Java
ReplyDelete* * *
* *
* * *
*
* *
* * *
How to write this pattern in java
ReplyDelete*
*
*
*
public class Program
Delete{
public static void main(String[] args)
{
for(int i=1;i<=4;i++)
{
System.out.print("*");
System.out.println();
}
}
}
program for following pattern
ReplyDeleteif n=4
output is:
1 2 3 4
9 10 11 12
13 14 15 16
5 6 7 8
Could u post a program for equilateral triangle
ReplyDeleteHow to write this pattern in java
ReplyDelete********
*aaaaaa*
*aaaaaa*
*aaaaaa*
*aaaaaa*
*aaaaaa*
********
public static void main(String args[])
Delete{
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("");
}
}
How to write this pattern in java? Pls. Answer me.
ReplyDelete*
*
* * *
* *
* *
how to write this pattern in java?
ReplyDelete******
********
**********
**********
**********
********
*****
can i get a program for this patter?
ReplyDelete*****
****
***
**
*
**
***
****
*****
public class Pattern2 {
Deletepublic 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();
}
}
}
/******************************************************************************
DeleteWelcome 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();
}
}
}
PLEASE HELP!!!!!!!!!
ReplyDeleteHow do i write this?
*^^^^^^^^*
**^^^^^^**
***^^^^***
****^^****
**********
*
ReplyDelete* *
* *
* * * * * * *
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.
ReplyDeleteBest java training in coimbatore
Android training in coimbatore
Networking training in coimbatore
Thanks for sharing this informative blog java training in OMR
ReplyDeleteThis article regarding Print Star Pattern in Java is common for every java learner and thanks for sharing above codes in java programming.
ReplyDelete* *
* * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
Please give code for above pattern Print Triangle of Stars in Java
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*
ReplyDelete**
***
use only one loop n solve this
I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks!
ReplyDeleteSS Total Anova Calculator
derivative calculator
Interval Calculator
edublackboards
very very important programs for java interviews. Thanks
ReplyDeleteThanks 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.
ReplyDeleteRead my Article: https://www.metapunk.to/hema_yadav_41/cracking-the-code-your-journey-into-the-world-of-programming-languages-27b