Minimum Boundary Element

Given a matrix of custom size the task is to print the minimum boundary element.

Example: Consider a matrix:-

11457
310213
56119

Here minimum boundary elements is 3.

Java
import java.util.*;
public class MinBoundaryElement
{
    public static void main(String args[])
    {
        int row=0,col=0,min=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter no.of rows: ");
        row=sc.nextInt();
        System.out.print("Enter no.of columns: ");
        col=sc.nextInt();
        int ar[][]=new int[row][col];
        System.out.println("Enter matrix elements:-");
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                ar[i][j]=sc.nextInt();
            }
        }
        min=ar[0][0];
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                if(i==0||i==row-1||j==0||j==col-1)
                {
                    if(ar[i][j]<min)
                    {
                        min=ar[i][j];
                    }
                }
            }
        }
        System.out.println("Minimum of boundary elements is "+min);
    }
}
Java