eyeoforion
04-12-2005, 12:11 AM
Ok here's the rub
The idea is to create a program which will extract words from a 'crossword' aka an array using stringbuffer, convert into a string and extract each word and print it without any trailing white space either side. Here's the array, any ideas on how to accomplish it?
public class crossword {
public static void main(String[] args) {
char[][] arrayOfChars = { { ' ',' ','J', 'A', 'V', 'A' },
{ 'I','S','', ' ', ' ', ' ' },
{ ' ',' ','L', 'O', 'T', 'S' },
{ ' ','O','F', ' ', ' ', ' ' },
{ ' ',' ','F', 'U', 'N', ' ' },
};
What I've worked out so far is the program will need to traverse the array pulling out its elements and putting them into a stringbuffer, going to require some sort of loop and a way to distinguish rows and columns.
The stringbuffer will then have to be converted to a string
Then the program will need to get rid of the spaces either side of the letters, using string.trim maybe.
Then somehow get each word out seperately and print it. My order may be a bit screwed but you get the generaly gist I hope.
Thanks in advance for any help, Orion
The idea is to create a program which will extract words from a 'crossword' aka an array using stringbuffer, convert into a string and extract each word and print it without any trailing white space either side. Here's the array, any ideas on how to accomplish it?
public class crossword {
public static void main(String[] args) {
char[][] arrayOfChars = { { ' ',' ','J', 'A', 'V', 'A' },
{ 'I','S','', ' ', ' ', ' ' },
{ ' ',' ','L', 'O', 'T', 'S' },
{ ' ','O','F', ' ', ' ', ' ' },
{ ' ',' ','F', 'U', 'N', ' ' },
};
What I've worked out so far is the program will need to traverse the array pulling out its elements and putting them into a stringbuffer, going to require some sort of loop and a way to distinguish rows and columns.
The stringbuffer will then have to be converted to a string
Then the program will need to get rid of the spaces either side of the letters, using string.trim maybe.
Then somehow get each word out seperately and print it. My order may be a bit screwed but you get the generaly gist I hope.
Thanks in advance for any help, Orion