Solved

Basic Array Functions

Posted on 2006-11-20
6
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 129
couple of eclipse 5 52
What's wrong with this code? 4 36
Bot application - advice 3 63
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

733 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