From 27fd1058fb0445457a65c7d011795c0234d0368d Mon Sep 17 00:00:00 2001 From: Dipti Singh <136192725+Diptigit11@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:12:11 +0530 Subject: [PATCH] Create starPyramidPattern.java 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. --- patterns/starPyramidPattern.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 patterns/starPyramidPattern.java diff --git a/patterns/starPyramidPattern.java b/patterns/starPyramidPattern.java new file mode 100644 index 0000000..b8af0b8 --- /dev/null +++ b/patterns/starPyramidPattern.java @@ -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(); + } + } +}