Boundary Elements

// Boundary Elements

public class Boundary
{public static void main(String args[])
{
int m[][]=new int [4][4];
int n=1,s=4,c=1,i=0,j=0;

while(n>=1)
{

do
{m[i][j]=c++;
n++;
j++;
}while(n<s);

n=0;

do
{m[i][j]=c++;
n++;
i++;
}while(n<s-1);

n=0;

do
{
m[i][j]=c++;
n++;
j–;
}while(n<s-1);

n=-1;

do
{m[i][j]=c++;
n++;
i–;
}while(n<s-2);

n=n-2;

}

for( i=0;i<s;i++)

{for( j=0;j<s;j++)

{ System.out.print(m[i][j]+" ");}

System.out.println();
}

}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s