# Need help with 2D array program. Crossing words

• 11-17-2008, 02:29 AM
busdude
Need help with 2D array program. Crossing words
I'm doing a program where the user inputs a list of words and the program arranges them into a 20 X 20 grid of chars, putting in the words that are possible.

Pasted instructions:
"
Write a program that will accept a list of words into an array list of strings, then make a 20 x 20 array of char that contains a crossword puzzle with these words.

For example, when given the list
addle, apple, clowning, incline, plan, burr
a p p l e
d
d
c l o w n i n g
e n
c
l
i
p l a n
e

EDIT: the above isn't displaying properly in the forum for some reason, still the idea is clear.

You may want to use the following method: Place the first word horizontally in the center of the grid. Place the next word vertically. Check if there is a common letter already on the grid, and if all the squares into which you want to place that word are still empty. (If you can't place it on any of the common letters, skip the word.) Then switch back to horizontal, place the next word if possible, and so on.
"

code so far:
Code:

```import java.util.ArrayList; import java.util.Scanner; class A2     {         public A2()         {             LIST = new ArrayList<String>();         }         public void addWord(String word)         {             LIST.add(word);                     }                 public void grid()         {             grid = new char[ROWS][COLUMNS];                         for (int i = 0; i < ROWS; i ++)                 for (int j = 0; i < COLUMNS; j++)                     grid[i][j] = ' ';                 }       public void insertFirstWord(String LIST)     {                                     }   /**     public char[][] drawGrid()     {                   return     } */ private ArrayList<String> LIST;                    private static final int ROWS = 20;       private static final int COLUMNS = 20;       private char[][] grid;      }            public class A2Tester     {         public static void main(String[] args)         {                         Scanner in = new Scanner(System.in);             System.out.println("Enter a list of words to be arranged in a crossword. Enter stop to end the list");                         A2 crossword = new A2();                               boolean done = false;         while(!done)             {                 String thing = in.nextLine();                          crossword.addWord(thing);                     if (thing.equalsIgnoreCase("Stop"))                 {done = true;}              }             } }```

I don't know how to start to put the first word in the array list into the grid. you have to seperate the string into chars. Also I'm not sure how to display the 2D array.

Anything I'm doing wrong so far?
• 11-17-2008, 02:43 AM
Fubarable
New To Java - Need help with 2d arrays program. crossing words program.

To the original poster, cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.
• 11-17-2008, 02:47 AM
busdude
It says in order to put links in my post I must have a post count of at least 20.

So I'd appreciate some actual help and not trolling informing everyone about Internet ethics.

Not to mention if I get more things, I would edit my post.
• 11-17-2008, 03:16 AM
Fubarable
So you call it "trolling" if someone posts information that helps you avoid pissing others off and will help you in the long run get more help? Good luck, you'll need it.