Solved

Dimensional Array

Posted on 2006-10-28
4
135 Views
Last Modified: 2010-03-31
How to create sub array with different length?

[0] - > [0]
[1] -> [0] [1]
[2] -> [0] [1] [2]
[3] -> [0] [1] [2] [3]
0
Comment
Question by:heyhey84
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
gkishoreji earned 21 total points
ID: 17827927
// initially define only one dimension
int[][] a = new int[4][];

for(int i = 0; i < 4; i++)
{
// when needed, initialize the second dimension with required number of elements
a[i] = new int[i+1];
}
0
 

Author Comment

by:heyhey84
ID: 17827971
After able created my sub array with different length
The initial one dimension array will be all null

if i want to insert a value

Insert value 1
[0] -> [value 1]
[1] -> null
[2] -> null
[3] -> null

Insert value 2
[0] -> [Value 2]
[1] -> [Value 1][]
[2] -> null
[3] -> null

How do i create this insertion of value? bigger value to be store on top
0
 

Author Comment

by:heyhey84
ID: 17828150
void insert(int n) {
          
          // i think this should create the correct size of array
        count = count + 1;
          a[count] = new int[count+1];
          
        // how to insert the value into the correct slot?                    
       
    }
0
 

Author Comment

by:heyhey84
ID: 17832206
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java array passed to SQL where clause 23 61
recursion example 16 111
Apps blocked by Java 9 59
Groovy problem when using SOAPUI : DispatchException occurred 7 27
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now