In this program we will display the following pattern:
1
2 2
3 3 3
4 4 4 4
n n n n n
4 4 4 4
3 3 3
2 2
1
public class A
{
int i,j,x,y;
public void show()
{
x=1;
y=1;
for(i=1;i<=9;i++)
{
for(j=1;j<=x;j++)
{
if(i==5)
System.out.print("n");
else
System.out.print(y);
}
if(i<=9/2)
{
y++;
x++;
}
else
{
y--;
x--;
}
System.out.println();
}
}
public static void main(String args[])
{
A ob=new A();
ob.show();
}
}
Related Post: BlueJ Programs On Pattern
No comments:
Post a Comment