Java program to print given Square Star Patten.

java program to print given star square pattern

package testjava.controlflow;

public class PrintSquareStar 
{
	public static void printSquareStar(int number)
	{
		if(number < 5)
		{
			System.out.println("Invalid Value");
		}
		else
		{
			for(int i = 1; i <= number; i++)
			{
				for(int j = 1; j <= number; j++) 
				{
					if((j == 1) || (j == number) || (i == 1) || 
					   (i == number) || (j == i) || (i == number - j + 1)) 
					{
						System.out.print("*");
					}
					else 
					{
						System.out.print(" ");
					}
				}
				System.out.println();
			}
		}
	}
	
	public static void main(String args[])
	{
		PrintSquareStar.printSquareStar(9);
	}
}