Solved

Basic Array Functions

Posted on 2006-11-20
6
183 Views
Last Modified: 2010-03-31
Hi,

I would like to know how to get the value of the position of the array..

E.g.
arr[i][j]

How would I get the value of the "i" and the "j" into a variable (two seperate ones)?

Note I don't want to know what the [i][j] have been assigned, but rather than the actual numerical value of "i" and "j"...

Thanks
0
Comment
Question by:vrameen
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17979101
>>How would I get the value of the "i" and the "j" into a variable (two seperate ones)?

i is an array
j is a variable

int[] row = arr[i];
int n = arr[i][j];
0
 

Author Comment

by:vrameen
ID: 17979217
I don't really understand..

To clarify my question...

arr[i][j] is a 2d array...

Say the array is now at arr[3][12] and arr[3][12] = "hello";
I want to get the number "3" and the number "12" into two separate variables..
I'm not interested in getting the string "hello", but rather the array numbers into the variable.

0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17979238
vrameen,

Are you wanting the upperbound that the 2d array is filled in?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
ID: 17979590
>>but rather the array numbers into the variable.

But they're already in variables i and j ..?

You can of course copy them

int x = i;
int y = j;
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17980531
If you are looking for the position where the array value is "hello", you can search for it

int x = -1;
int y = -1;

for(int i=0; i<arr.length; i++) {
    for(int j=0; i<arr[i].length; j++) {
        if("hello".equals(arr[i][j])) {
            x = i;
            y = j;
            break;
        }
    }
}


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18037612
:-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

15 Experts available now in Live!

Get 1:1 Help Now