Results 1 to 3 of 3

Thread: Array

  1. #1
    IT student is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default 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. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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. #3
    Join Date
    Aug 2007
    Posts
    45
    Rep Power
    0

    Smile [Solved] 2-D Array

    Quote Originally Posted by IT student View Post
    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.
    Please don't put such kind of problems into Advanced Java category. You should ask your easy questions into New to Java Forums.

    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.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    
    public class Array2D {
    	public static void main (String[] args) {
    		//get value of N
    		int N;
    		try{
    			BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
    			String sForN=buffer.readLine();
    			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;
        }
    }

Similar Threads

  1. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  2. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  3. How to transfer 1D array in JAVA to 3D array in C
    By fishwater00 in forum New To Java
    Replies: 0
    Last Post: 07-31-2009, 06:24 PM
  4. Replies: 1
    Last Post: 03-31-2009, 06:40 AM
  5. String array to byte array?!
    By Joe2003 in forum Advanced Java
    Replies: 5
    Last Post: 02-28-2009, 06:09 AM

Posting Permissions

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