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

Star Patterns using Java
Star Patterns using Java

Program :

Write a program to print following pattern

Solution :

Here is the Java code to print 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( i+j>=4 && j-i>-5) //
				{
					System.out.print("*");
				}
				else
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Leave a Reply