Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array problem

 
peterx peter
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand your question. Do you want to do that with the existing method or add an extra method?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code isn't quite what you're looking for, but it should give you an idea of how you might approach this problem.

You could adapt the method to take two arguments: The number you want to match, and which match you want (1st, 2nd, 3rd, etc.).

The method could have a variable to count the number of matches. Then when you find a match and the count is where you want it, return that index. Otherwise, return -1 to indicate that it wasn't found.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic