* Pattern program 1:
public class star1 {
public static void main(String args[]){
for(int i=0;i<4;i++){
for(int j=0;j<=4;j++){
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT:
*****
*****
*****
*****
* Pattern program 2:
public class star2 {
public static void main(String args[]){
for(int i=0;i<4;i++){
for(int j=0;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT:
*
**
***
****
* Pattern program 3:
public class star3 {
public static void main(String args[]){
for(int i=0;i<5;i++){
if(i==0||i==4){
for(int j=0;j<5;j++){
System.out.print("*");
}System.out.println();
}else{
for(int k=0;k<5;k++){
if(k==0||k==4){
System.out.print("*");
}
else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
OUTPUT:
*****
*
*
*
*
*
*
*****
* Pattern program 4:
public class star4 {
public static void main(String args[]){
for(int i=1;i<=5;i++){
for(int j=0;j<5-i;j++)
System.out.print(" ");
for(int l=1;l<=i;l++)
System.out.print("*");
System.out.println();
}
}
}
OUTPUT:
*
**
***
****
*****
* Pattern program 5
public static void main(String args[]){
System.out.println("The Pattern
is");
for(int i=1;i<=5;i++)
{
for(int j=i;j<=5;j++)
{
System.out.print("*");
}
System.out.println();
}
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("+");
}
System.out.println();
}
}
}
OUTPUT:
*****
****
***
**
*
+
++
+++
++++
+++++
* Pattern program 6
public class star6 {
public static void main(String args[]){
for(int i=0;i<5;i++){
for(int j=i;j<5;j++){
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT:
*****
****
***
**
*
* Pattern program 7
public class star7 {
public static void main(String args[]){
for(int i=0;i<5;i++){
for(int j=0;j<=i;j++){
System.out.print("*");
}
System.out.println();
}
for(int i=0;i<5;i++){
for(int j=i;j<5;j++){
System.out.print("*");
}
System.out.println();
}
}
}
OUTPUT:
*
**
***
****
*****
*****
****
***
**
*
You may also like to read to about:
how to print pascal triangle ?
ReplyDeleteHi Reader,
DeletePlease find the link to printing Pascal triangle in java given below:
https://javaradar.blogspot.com/2017/10/pascal-triangle-in-java.html
You can also find the link at the end of this post.