This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes 2D array: Find an array of characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2D array: Find an array of characters" Watch "2D array: Find an array of characters" New topic

2D array: Find an array of characters

Scotty Young

Joined: Oct 26, 2006
Posts: 10
I'm working on a problem to help try and improve my java skills before I sit SCJA:

I have an array, "word", with three characters "D" "O" and "G".

I'm trying to search through a larger 2D array and then print out all three characters when they are matched in a row.

I have worked this out on a white board with someone before, but I cant remember how I solved it... derp.

This is the code I currently have:

I feel like I'm close to solving it.>
Greg Brannon

Joined: Oct 24, 2010
Posts: 563
How close? What's your program doing now? What should it be doing?

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Scotty Young

Joined: Oct 26, 2006
Posts: 10
Well, I'm trying to get it to output DOG. At the minute its outputting DDODDDOG.

I thought I knew what I was doing but now I'm a bit lost and confused. I want it to compare every single character in square to the characters in word, and output the characters that match, but only if it finds them in the sequence D-O-G.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 713

I know we're not supposed to give out "answers" but I couldn't resist giving this a try. Works for any size 'square' and 'word'. Prints out list of square coordinates where 'd-o-g' was found.

When I was your age I was toggling in the bootstrap code on the front panel
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: 2D array: Find an array of characters
It's not a secret anymore!