I'll look at how to make a square pattern with Java programming. In the console, we'll write a Java program that generates a square pattern of asterisks (*). This pattern is a popular starting exercise that can help you grasp nested loops and fundamental control flow in Java.
[ 1 ].. Square pattern in Java
[ 2 ].. Hollow Square pattern
[ 3 ].. Left triangle star pattern
[ 4 ].. Right triangle pattern
[ 5 ].. Left Down Triangle
[ 6 ].. Right Down Triangle
[ 7 ].. Hollow triangle star pattern
[ 7 ][ a ].. Hollow triangle star pattern
[ 7 ][ b ].. Hollow triangle star pattern
[ 7 ][ c ].. Hollow triangle star pattern
[ 8 ].. Right pascal star pattern
[ 9 ].. Cross pattern program
[ 10 ].. Pyramid star pattern
[ 10 ][ a ].. Pyramid number pattern
[ 10 ][ a ].. Pyramid Alpha pattern
[ 10 ][ a ].. Pyramid Alpha pattern
[ 10 ][ a ].. Pyramid Alpha pattern
[ 11 ].. Heart pattern
public class Main
{
public static void main(String[] args) {
int size = 7;
for(int row =1; row<=size; row++)
{
for(int col=1; col<=size; col++)
{
if((row==1&& (col == 2 || col==6)) ||
(row==2 && (col == 1 || col==3 || col==5|| col==7)) ||
(row==3 && (col == 1 || col==4 || col==7)) ||
(row==4 && (col == 1 || col==7)) ||
(row==5 && (col == 2 || col==6)) ||
(row==6 && (col == 3 || col==5)) ||
(row==7 && (col == 4)))
{
System.out.print("* ");
}
else
{
System.out.print(" ");
}
}
System.out.println(" ");
}
}
}