import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
// Print Boundary
public static void printBoundary(int [][] mat){
int n = mat.length;
//Top wall : row fixed = 0
for(int c=0 ; c<= n-2 ; c++){
System.out.print(mat[0][c] + " ");
}
//Right wall : col fixed = n-1
for(int r=0; r<=n-2; r++){
System.out.print(mat[r][n-1] + " ");
}
//Bottom wall : Row fixed = n-1
for(int c=n-1 ; c >=1 ; c--){
System.out.print(mat[n-1][c] + " ");
}
//Left wall : Col fixed = 0
for(int r =n-1 ; r>=1 ; r--){
System.out.print(mat[r][0] + " ");
}
}
public static void main(String[] args) {
int[][] mat = {
{1, 2 , 3 , 4 },
{5, 6 , 7 , 8 },
{9, 10 , 11, 12 },
{13 , 14 , 15 , 16 }
};
printBoundary(mat);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: