Share this post on:

Here you find Different Patterns in Java, It will be in Different shape and consists of two or more loops.

  1. Patterns in Java

public class Practice {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Pattern “+”\n”);

for(int i=1; i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(“*”);
}
System.out.println();
}

}

}

Output:

Patterns in Java

2. Pattern in Java

public class Practice {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Pattern “+”\n”);
for(int i=1; i<=5;i++)
{
for(int j=5;j>=i;j–)
{
System.out.print(“*”);
}
System.out.println();
}

}

}

Output:

Pattern in Java

3. Pattern in Java

public class Practice {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Pattern “+”\n”);
for(int i=1; i<=5;i++)
{
for(int j=5;j>=i;j–)
{
System.out.print(” “);
}
for(int k=1;k<=i;k++)
{
System.out.print(“*”);
}
System.out.println();
}

}

}

Output:

Pattern in Java

4. Pattern in Java

public class Practice {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(“Pattern “+”\n”);
for(int i=1; i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(” “);
}
for(int k=4;k>=i;k–)
{
System.out.print(“*”);
}
System.out.println();
}

}

}

Output:

Pattern in Java

5. Pattern in Java

public class Practice
{
public static void main(String args[])
{
int n, i, j, space = 1;
System.out.print(“Enter the number of rows: “);
Scanner s = new Scanner(System.in);
n = s.nextInt();
space = n – 1;
for (j = 1; j<= n; j++)
{
for (i = 1; i<= space; i++)
{
System.out.print(” “);
}
space–;
for (i = 1; i <= 2 * j – 1; i++)
{
System.out.print(“*”);
}
System.out.println(“”);
}
space = 1;
for (j = 1; j<= n – 1; j++)
{
for (i = 1; i<= space; i++)
{
System.out.print(” “);
}
space++;
for (i = 1; i<= 2 * (n – j) – 1; i++)
{
System.out.print(“*”);
}
System.out.println(“”);
}
}
}

Patterns in Java

6. Pattern in Java

public class Practice
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the number of rows: “);

int rows = sc.nextInt();
for (int i= 0; i<= rows-1 ; i++)
{
for (int j=0; j<=i; j++)
{
System.out.print(” “);
}
for (int k=0; k<=rows-1-i; k++)
{
System.out.print(“*” + ” “);
}
System.out.println();
}
sc.close();

}

}

Output:

Patterns in Java

7. Pattern in Java

public class Practice
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the number of rows: “);

int rows = sc.nextInt();
for (int i= 0; i<= rows-1 ; i++)
{
for (int j=0; j<=i; j++) { System.out.print(“*”+ ” “); } System.out.println(“”); } for (int i=rows-1; i>=0; i–)
{
for(int j=0; j <= i-1;j++)
{
System.out.print(“*”+ ” “);
}
System.out.println(“”);
}
sc.close();
}

}

Output:

Patterns in Java

8. Pattern in Java

public class Practice
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the number of rows: “);

int rows = sc.nextInt();
for (int i= 0; i<= rows-1 ; i++)
{
for (int j=0; j <i; j++)
{
System.out.print(” “);
}
for (int k=i; k<=rows-1; k++) { System.out.print(“*” + ” “);

}

System.out.println(“”); } for (int i= rows-1; i>= 0; i–)
{
for (int j=0; j< i ;j++)
{
System.out.print(” “);
}
for (int k=i; k<=rows-1; k++)
{
System.out.print(“*” + ” “);
}
System.out.println(“”);
}
sc.close();
}

}

Output:

Pattern in Java
Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

Leave a Comment

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