Star Pyramid Pattern Program in Java

  • by

Star pyramid pattern programs in java or in any computer language helps programmer / developer to build logic.

Program -: 1
package basic;

public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i =0; i<5; i++)
{
for (int j=0; j<i; j++)
{
System.out.print(“*”);
}
System.out.println(” “);
}
}

}
Output -:

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

Program -: 2
public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i =4; i>=0; i–)
{
for (int j=0; j<=i; j++)
{
System.out.print(“*”);
}
System.out.println(” “);
}
}
}
Output -:
*****
****
***
**
*

Program -: 3
public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
int sp=4;
for (int i =0; i<4; i++)
{

for (int k=sp; k>=1; k–)
{
System.out.print(” “);
}

for (int j=0; j<=i; j++)
{
System.out.print(” *”);
}
sp–;
System.out.println();
}
}
}
Output -:
*
* *
* * *
* * * *

Program -: 4
public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
int sp=4;
for (int i =0; i<4; i++)
{
for (int k=sp; k>=1; k–)
{
System.out.print(” “);
}
for (int j=0; j<=i; j++)
{
System.out.print(“*”);
}
sp–;
System.out.println();
}
}
}

Output -:
*
**
***
****

Program -: 5
public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
int sp=1;
for (int i =4; i>=0; i–)
{
for (int k=sp; k>=1; k–)
{
System.out.print(” “);
}
for (int j=0; j<=i; j++)
{
System.out.print(“*”);
}
sp++;
System.out.println();
}
}
}

Output -:
*****
****
***
**
*

Program -: 6
public class StarPattern {

public static void main(String[] args) {
// TODO Auto-generated method stub
int k=0;
for (int i =1; i<=5; i++)
{
for (int j=1; j<=i; j++)
{
if(k%2 == 0)
{
System.out.print(“$”);
}
else
{
System.out.print(“#”);
}
k++;
}
System.out.println(“\n”);
}
}
}
Otput -:
$

#$

#$#

$#$#

$#$#$

For number star alphabet pattern programs in c

Leave a Reply