**Question:**

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

For example:

**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 m=Integer.parseInt(br.readLine()); System.out.print("Enter the no. of columns: "); //Inputting the number of columns n=Integer.parseInt(br.readLine()); int A[][]=new int[m][n]; //Creating the array /* Inputting the array */ for(i=0;i<m;i++) { for(j=0;j<n;j++) { System.out.print("Enter the elements: "); A[i][j]=Integer.parseInt(br.readLine()); } } System.out.println("The Boundary Elements are:"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(i==0 || j==0 || i == m-1 || j == n-1) //condition for accessing boundary elements System.out.print(A[i][j]+"\t"); else System.out.print(" \t"); } System.out.println(); } } }

**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’.

**Output:**

what is the function of “t”? Thanks.

“t” is used for giving “Horizontal Tab spaces”

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

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

See: http://www.guideforschool.com/1705172-java-program-to-fill-a-2-d-array-with-prime-numbers/

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 🙂

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…

The glitch was corrected. Thanks Sayan for pointing that out. 🙂