Home / Blue J / java program for pattern#6

java program for pattern#6

Java program for printing the following pattern:
    *
   ***
  *****
 *******
This program also have indentation. Indentation required depends on the output needed and here indentation requires is: for row 1:  total 4 spaces and then 1 start row 2: total 3 spaces and 3 stars row 3: total 5 spaces and 5 stars……. So on  So here spacing is decreasing by 1. Stars/asterisk increases by two starting with 1.
So step 1: print spacing (with decreasing loop variable)
step 2: print asterisk (with increasing loop variable)
class format5
{
public static void main(String args[])
{
int i,j,k=1;                                                                            

for(i=1;i<5;i++)
{
for(j=5;j>=i;j--)    // printing the space which is dependent on i;
System.out.print(' '); 

for(j=1;j<2*i;j++)   /for printg the required asterisk/star
System.out.print("*");

System.out.println();
}
}
}

 OUTPUT:


Tags: java program for pattern making,  program for star pattern in java,bluej, making star pattern in java/bluej/c/c++

Check Also

Program to check Upper Triangular matrix

What is Upper Triangular Matrix?  An upper triangular matrix is a square matrix in which ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.