Use Multidimensional Array for Storing Data

Asked By 10 points N/A Posted on -
qa-featured

How can I use multidimensional array for storing and retrieving data? I only need to store and retrieve 5 data temporarily so using SQL would be a waste of time, moreover, this is just for simulation. Can you give some examples?

SHARE
Answered By 0 points N/A #108179

Use Multidimensional Array for Storing Data

qa-featured

Hi Arthuro,

 

Take a look at this code sample:

 

 

/**
 * Write a description of class d2_array here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class d2_array
{
    // instance variables – replace the example below with your own
    private int x;
 
    /**
     * Constructor for objects of class d2_array
     */
    public d2_array()
    {
     String[][] Data;
 
     Data = new String[5][5]; // 5 rows and 5 columns
 
     //Assign the values, do it either dynamically or statically
 
     //For first flow
 
    // add random values to the 2d array
     Data[0][1] = "1";
     Data[0][2] = "5"; 
     Data[1][0] = "3";
     Data[1][1] = "7";
     Data[1][2] = "6";
 
     //printing
 
     for(int i=0;i<2;i++)
 
     {
 
         for(int j=0;j<3;j++)
 
         {
  
             System.out.print(Data[i][j]+"n");
  
         }
 
         //System.out.print("n");
        }
}
 
I hope it helps.
 
 

Login/Register to Answer

Related Questions