Star Patterns with Java ! Easy Way | Simple Trick

java program to print pattern
java program to print pattern

Program :

Write a program to print following pattern .

Simple Star pattern

Code :

Below java program will print above pattern.

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

Leave a Reply