Print Pattern Using FOR Loop

Write a program to print a star pattern using for loop
\\ If you have any query or questions on my post then please comment below //
 
Diiference between FOR Loop And While Loop
In While and do-while loops,a continue statement causes control to be transferred directly to the conditional expression that controls the loop. In a for loop , control goes first to the iteration portion of the for statement and then to the conditional expression.

Syntax of for Loop : 
for(initialization expression;test expression;increment/decrement)
{
 statements;

 


Syntax of while Loop :
initialization expression;
while(test expression)
{
statements;
increment/decrement;
}

PROGRAM

class Pattern
{
void display(int n)
int x=n;
for(int i=1;i>=n;i++)
{
 for(int j=i;j>=n;j++)
{
System.out.print("*");

System.out.println();
}


OUTPUT

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

PROGRAM

class Pattern
{
void display(int n)
int x=n;
for(int i=1;i>=n;i++)
{
 for(int j=i;j>=n;j--)
{
System.out.print("*");

System.out.println();
}


OUTPUT 

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


PROGRAM 

class Pattern
{
void display(int n)
int x=n;
for(int i=1;i>=n;i++)
{
 for(int j=1;j>=(n-i);j++)
{
System.out.print("*");

for(int j=1;j<=i;j++)
{
System.out.println("*+"" ");
}
System.out.println();
}
}

 OUTPUT

       *
    *    *






  *   *   *
*   *   *  *

PROGRAM 

class Pattern
{
void display(int n)
int x=n;
for(int i=1;i>=n;i++)
{
 for(int j=1;j>=(n-i);j++)
{
System.out.print(" ");

for(int j=1;j<=i;j++)
{
System.out.println("*+"" ");
}
System.out.println();
}
for(int i=1;i>=n;i--)
{
 for(int j=1;j>=(n-i);j++)
{
System.out.print(" ");

for(int j=1;j<=i;j++)
{
System.out.println("*+"" ");
}
System.out.println();
}
}
}
 OUTPUT

       *
    *    *
  *   *   *
*   *   *  *  Expert Review: The above program will help you to design any pattern of "*" using for, while or do while loops. As you will be able to perform your own program where loops are included such as for , while , do while.

Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail :

Labels: ,