Tuesday , 26 March 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 : www.javaforschool.com
* @Program Type : BlueJ Program – Java

import java.io.*;
class Boundary_Element
public static void main(String args[])throws IOException
int i,j,m,n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

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 */
for(i=0;iNote: 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

Infix Postfix Prefix Conversion – Correct Method (ISC Computer Science)

In this video we discuss about the correct way of converting an Infix Expression to Postfix and Prefix.


  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 *