Pattern Program #4 || Number Pattern in JAVA || BluejCode
Pattern Program #4
Pattern 1 |
Pattern 2 |
Pattern 3 |
Program :-
Pattern 1 :-
class Pattern1
{
public static void main(String args[])
{
int i,j,a=2;
for(i=1;i<=5;i++) // Loop for No. of rows
{
for(j=1;j<=i;j++) //Loop for No. of columns
{
if(i==5)
{
a=1;
System.out.print(a+"\t");
}
else
{
System.out.print(a+"\t");
}
}
System.out.println();
a++;
}
}// end of main method
}// end of classPattern 2 :-
class Pattern2{
public static void main(String args[])
{
int i,j,a=2;
for(i=5;i>=1;i--) // Loop for No. of rows
{
for(j=1;j<=i;j++) //Loop for No. of columns
{
if(i==1)
{
a=1;
System.out.print(a+"\t");
}
else
{
System.out.print(a+"\t");
}
}
System.out.println();
a++;
}
} // end of main method
} // end of class
Pattern 3 :-
class Pattern3
{
public static void main(String args[])
{
int i,j,a=2;
for(i=1;i<=5;i++) // Loop for No. of rows
{
for(j=1;j<=5;j++) //Loop for No. of columns
{
if(i==5)
{
a=1;
System.out.print(a+"\t");
}
else
{
System.out.print(a+"\t");
}
}
System.out.println();
a++;
}
} // end of main method
} // end of class
Comments
Post a Comment