Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
53K views

Java Program To Print Pyramid Pattern of Stars

This Java program prints a pyramid pattern of stars with increasing spacing between stars. It uses nested for loops, where the outer loop controls the rows and inner loops handle spacing and printing stars. The program initializes a count variable, then loops to print rows with stars separated by the count that increases by two each iteration, producing a triangular pyramid shape.

Uploaded by

Sanjay Dudani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53K views

Java Program To Print Pyramid Pattern of Stars

This Java program prints a pyramid pattern of stars with increasing spacing between stars. It uses nested for loops, where the outer loop controls the rows and inner loops handle spacing and printing stars. The program initializes a count variable, then loops to print rows with stars separated by the count that increases by two each iteration, producing a triangular pyramid shape.

Uploaded by

Sanjay Dudani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*Program to print following pattern-

*
* *
* * *
* * * *
* * * * *

*/

public class Stars


{
public static void main(String args[])
{
int c=1;
for(int i=1;i<=5;i++)
{
for(int j=i;j<5;j++)
{
System.out.print(" ");
}
for(int k=1;k<=c;k++)
{
if(k%2==0)
System.out.print(" ");
else
System.out.print("*");
}
System.out.println();
c+=2;
}
}
}

You might also like