Friday , 18 January 2019
Home » Array Related Programs » Java Program to print Boundary Elements of a 2D Array

Java Program to print Boundary Elements of a 2D Array


Write a Program in Java to input a 2-D array of size ‘m*n’ and print its boundary (border) elements.

For example:

boundary elements

Programming Code:

* The class Boundary_Element accesses and prints the boundary elements of a 2D array
* @author :
* @Program Type : BlueJ Program - Java

class Boundary_Element
    public static void main(String args[])throws IOException
        int i,j,m,n;
        BufferedReader br=new BufferedReader(new InputStreamReader(;

        System.out.print("Enter the no. of  rows: "); //Inputting the number of rows
        System.out.print("Enter the no. of columns: "); //Inputting the number of columns

        int A[][]=new int[m][n]; //Creating the array
        /* Inputting the array */
                System.out.print("Enter the elements: ");
        System.out.println("The Boundary Elements are:");
                if(i==0 || j==0 || i == m-1 || j == n-1) //condition for accessing boundary elements
                    System.out.print(" \t");

Note: If you are asked to input a square matrix of size ‘n*n’ then just input the value of ‘n’ and replace ‘m’ and ‘n’ in the above program with ‘n’.


boundary elements output

Check Also

How to read an Ammeter – ISC Physics Practical

Solution of ISC 2017 Computer science Paper as provided by the Council for the Indian School Certificate Examinations.


  1. Chirag Pandey Bose

    what is the function of “t”? Thanks.

  2. its really helpfull….thanx a lot….dude….

  3. Sir, Can you give the method for filling an array with a particular type of number ? I am stuck at that.

  4. Thankyou soo much maam/sir fr this program..ur blog is really really veryy helpful i have prepared fr my boards practical only with the help of it thankyou 🙂

  5. plz tell what is the condition for the validation of a date???

    if condition is given,

    if(d>0&&d<=month[m] && m>0&&m<=12 && y>0 && y<=9999)


    then while random checking,if d and y doesn’t satisfy condition,it returns invalid input,while if month is not satisfied,it returns array index out of bounds exception… as in the case of ur posts… future date…


    so plz go through and solve this problem of mine…

Leave a Reply

Your email address will not be published. Required fields are marked *