Skip to content

Commit

Permalink
Create starPyramidPattern.java
Browse files Browse the repository at this point in the history
This Java code is designed to create a pyramid pattern made of stars. It uses two loops to achieve this:
The outer loop, controlled by the variable i, runs from 1 to the desired height of the pyramid (specified by the value of n).
The inner loop, controlled by the variable s, prints spaces before the stars. The number of spaces decreases as you move down the pyramid.
For each row, it first prints spaces to create an indentation on the left side and then prints stars (asterisks) to form the pyramid. The number of stars increases with each row.

By adjusting the value of n, you can control the height of the pyramid. The program creates a visually pleasing pyramid pattern.
  • Loading branch information
Diptigit11 authored Oct 11, 2023
1 parent 6ad3692 commit 27fd105
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions patterns/starPyramidPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.*;

public class starPyramidPattern {
public static void main(String[] args) {
int n = 5; // we can Change this value to adjust the height of the pyramid

for (int i = 1; i <= n; i++) {
// Print spaces
for (int s = 1; s <= n - i; s++) {
System.out.print(" ");
}

// Print stars
for (int j = 1; j <= i * 2 - 1; j++) {
System.out.print("*");
}

// Move to the next line after each row
System.out.println();
}
}
}

0 comments on commit 27fd105

Please sign in to comment.