[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Searching 2d array via Rows

The Task:
-----------------------
int findFirstInRow(int rowNum, double value)      Search the specified row for the first occurrence of value.
                              When you find the first occurrence of value, return the column
                                        number at which it is located.  If you do not find value in
                              the row, return -1 to indicate this.

The Question:
-----------------------
I've searched arrays before, but have no guidance on 2d arrays and specifying a specific row.  How do I approach breaking this down.  Algorithms plz.
0
smkJackstraw
Asked:
smkJackstraw
  • 2
1 Solution
 
objectsCommented:
A 2d array is an array of arrays, so get the array for a specific row you would use:

double[][] M = ...;   // the 2-d array
double[] row = M[rowNum];
0
 
smkJackstrawAuthor Commented:
Wouldn't the rows and column be integers?  Where as the value in any index be a double.


Would this be specified: double[][] M = M[int rowNum][0];




0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now