1. Member
Join Date
Oct 2009
Posts
6
Rep Power
0

## Array

hello every one
I am IT student and i face a problem to solve this java program i will be glade if any one can help me question is

Create a 2D array (also called as Matrix) of size NxN.
Display the 2D array.
Create a 2D array of size 2x2 and initialize it with some integer values.

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
Hi and welcome to Java Forums.

I don't really think anyone is going to write your code for you. It would be no fun for you if they did! But there will always be people able to help if you get stuck and post your code and questions. (why you get a particular compiler error, or why you get output that you don't expect etc).

Have a read of Arrays in Sun's Tutorial - or other parts of the Language Basics section.

Good luck!

3. Member
Join Date
Aug 2007
Posts
45
Rep Power
0

## [Solved] 2-D Array

Originally Posted by IT student
hello every one
Create a 2D array (also called as Matrix) of size NxN.
Display the 2D array.
Create a 2D array of size 2x2 and initialize it with some integer values.

However since you really want to know about JAVA (you must read book first). We all welcome to you in JAVA world with solving your problem related to array in JAVA; here is code:-
Java Code:
```/**
* @(#)Array2D.java
*
* @created 19-Oct-2009 4:00 pm
* @author Gajesh
* @version 1.00 2009/10/19
*/

import java.io.IOException;

public class Array2D {
public static void main (String[] args) {
//get value of N
int N;
try{
N=Integer.parseInt(sForN);
//N=Integer.valueOf(sForN).intValue();
}catch(NumberFormatException e) {
System.out.println ("you entered invalid entry for N");
return ;
}catch(IOException ioe) {
System.out.println ("An IOException is occured during reading data from consol");
return ;
}
//create a 2-D array
Object arr[][]=new Object[N][N];
//initialize the 2-D array
for (int i = 0; i<N; i++)
for (int j = 0; j<N; j++)
arr[i][j]=i*i;
//display the 2-D array
System.out.println ("~~~~ 2-D Array of N*N ~~~~");
for (int i = 0; i<N; i++) {
for (int j = 0; j<N; j++)
System.out.print (arr[i][j]+" ");
System.out.println ();
}
//
//2-d array of 2*2 and initialize it with integer value
int [][] int2D_array=new int[2][2];
for (int i = 0; i<2; i++)
for (int j = 0; j<2; j++)
int2D_array[i][j]=i*j;
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•