Program to print given star pattern in Java using simple Trick !

Star Patterns
Star Patterns

Problem :

Write a program to solve given pattern .

Pattern in Java

Solution :

Here is the code to solve the given pattern .

public class Pattern {
	public static void main(String[] args) {
		for (int i = 0; i <9; i++) {
			for (int j = 0; j < 5; j++) {
				if(  j-i<=-4 || i+j<=4) //
				{
					System.out.print("*");
				}
				else
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Leave a Reply